If yes then echo this, if no echo that in PHP-simple array?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rdbrock
    New Member
    • Jan 2010
    • 10

    If yes then echo this, if no echo that in PHP-simple array?

    Hello,

    Can anyone help me complete this? Is this an array?

    Code:
    <?php
    $Choice1 = $_POST['Choice1'];
    $Choice2 = $_POST['Choice2'];
    $Nothing = $_POST['Nothing']
    I have an HTML file that will have a radio button and a text input
    that looks like this.

    Would you like to help me?
    Yes or No
    If yes, post choice 1
    if no, post choice 2.
    If left blank show nothing.....
  • rdbrock
    New Member
    • Jan 2010
    • 10

    #2
    please go easy on me, i'm new :)

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      doesn’t assigning the appropriate values do the trick?

      Comment

      • rdbrock
        New Member
        • Jan 2010
        • 10

        #4
        well, sorry about this, I failed to mention that I would like to have a multiple question. Would be like this.

        Would you like to help me now?
        If yes , post choice 1
        if no , ask another question.
        Thanks for helping, please choose 2 options
        Yes or no.

        Then post :

        # $Choice1 = $_POST['Choice1'];
        # $Choice2 = $_POST['Choice2'];
        # $Nothing = $_POST['Nothing']

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          what does the according HTML look like? (hard to imagine right now)

          Comment

          • rdbrock
            New Member
            • Jan 2010
            • 10

            #6
            does that make any sence?

            I'm just trying to ask a question if value" NO" then SHOW " another question"
            if YES or NO then display $whatever value.....

            I would only like the second question to display only if you selected "NO" so it will need to hide. Is this possible with PHP ? or do I need a JAVA script?

            Comment

            • rdbrock
              New Member
              • Jan 2010
              • 10

              #7
              I'm not exactly sure to ask the 2nd question in HTML or I guess to hide it

              [code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
              <html>
              <head>
              <form form action="help.ph p" method="post">
              <form>


              <b>Would you like to help me?</b>

              <input type="radio" name="group1" value="Yes"> Yes<br>
              <input type="radio" name="group2" value="Water"> No<br>

              <input name="Choice1" type="text" /> [/code]
              Last edited by Atli; Jan 28 '10, 10:01 AM. Reason: Changed [quote] tags to [code] tags.

              Comment

              • code green
                Recognized Expert Top Contributor
                • Mar 2007
                • 1726

                #8
                You need common name attributes when using radio buttons
                Code:
                <input type="radio" name="group" value="Yes"> Yes<br>
                <input type="radio" name="group" value="Water"> No<br>

                Comment

                • rdbrock
                  New Member
                  • Jan 2010
                  • 10

                  #9
                  Thanks for correcting that. Is there a way to hide a question in HTML?

                  Comment

                  • zorgi
                    Recognized Expert Contributor
                    • Mar 2008
                    • 431

                    #10
                    I am not sure if this code is here just by copy/paste accident

                    Code:
                    <form form action="help.php" method="post">
                    <form>
                    but just in case it probably should look like this:

                    Code:
                    <form action="help.php" method="post">
                    </form>
                    Notice closing <form></form>
                    And also all of your form elements (like radios) should be within those tags. Now.... I do not think this are php issues at all

                    Comment

                    • rdbrock
                      New Member
                      • Jan 2010
                      • 10

                      #11
                      Thanks, for that , that was a typo too. I'm just not good at details :) I do have the script working just fine,my problem is that I'm trying to incorporate if you choose "NO" on the radio button, I'd like for a HTML/PHP to show another "Text" or "Ask " another question. I'm thinking about a list function. But it did not work, how I wanted it to. Perhaps I don't know what function it suitable for what I am trying to accomplish.

                      Code:
                      <?php
                      $my_array = array(Yes","No","Nothing");
                      
                      list($Choice1, $Choice2, $Nothing) = $my_array;
                      echo "You selected Choice #2, the 2nd question would should here $Choice1, a $Choice1 and a $Nothing.";
                      ?>
                      I feel like I'm still missing something here.
                      Last edited by rdbrock; Jan 28 '10, 10:23 AM. Reason: CODE

                      Comment

                      • rdbrock
                        New Member
                        • Jan 2010
                        • 10

                        #12
                        I think I may have got it.
                        Could I use this or is there another easier way to do this?
                        Example 1 question depending on answer ask another question and so on.

                        Code:
                        >?php
                        $my_array = array("My Question #1 ","My Question # 2"," No question-blanks");
                        
                        list($a, , $c) = $my_array;
                        echo "Here I only use the $a and $c variables.";
                        ?>
                        
                        The output of the code above will be:
                        Here I only use the My Question #1 and No question-blanks.

                        Comment

                        • rdbrock
                          New Member
                          • Jan 2010
                          • 10

                          #13
                          Zorgi or code green, would you guys be able to help me understand how to get a Multiple Yes or No Question in HTML to work with the array I built using selective questions if chosen " no or "yes" to show the output on the array following another question
                          to display anything on the array?
                          I think this would solve the problem, if the List function /array is the way to go for Yes or No, then multiple questions based on yes or no selection.

                          Thanks much!

                          Comment

                          • rdbrock
                            New Member
                            • Jan 2010
                            • 10

                            #14
                            Or anyone else that understands in this matter.

                            Comment

                            Working...