Hi guys,

i have encountered a problem with php coding, hope you guys will be able to help me out 🙂

if ($result) {
while ($row = mysql_fetch_array($result)) {
$a = $row[a];
$b= $row;
$c = $row[c];

echo"<label><input type=\"radio\" name=\"RadioGroup1\" value=\"$a\">a:$a,</td><td>$b</td><td>$c</label><br>";

}
echo"<tr><td><input type=\"submit\" name=\"Submit\" value=\"Submit\"></td></tr>";
}

------------------------------------------------------------------------------
I am running trying to run a while loop that draws a value from a table, and attach it to a radio button.

The problem is that when I select a radio button and submit it, the value that is sent over to the next page is that of the last value drawn from while loop.

How do I ensure that the information to be sent over is of that I require?

Thank you for your time!

Cheers
t-bonist

    ... it looks like your putting in $a for VALUE as a string, which means its value will be just that: the dollar sign and the letter a. I can more or less see what you're trying to do, but it's perhaps a little early in the morning ... you can't just drop the quotes (well you can, but it's bad practice). The escaped quotes are making $a into a string rather than a value.

    In any case, a radio button can only be Boolean (true/false; 1/0). If the option is to have different values, you need checkboxes. As far as I can make out, you're trying to give the radio button several different values.

    Or have I misunderstood as usual?

    Norman

      HI Norman,

      Yup, I am trying to give a different values to each of the radio buttons drawn.

      I think the problem here is that the values of the radio buttons are the same, $a. Am like hoping that each radio button would have a specific $a value after each while loop.

      Thanks for your advice!! think i would give the checkboxes a try 🙂

      Cheers
      Bob

        Sorry, my previous post was garbled nonsense. You can use radio buttons, but you have to be careful how you do it. I ran into this one the first time I tried making a form. The deal is - you need the same entry for NAME for each button (otherwise they're all clickable simultaneously, like checkboxes) and your validation has to operate on a yes/no test for each button, so you can have:

        Do you like ice-cream?: yes / no / only strawberry / only chocolate

        Which would look like this:

        <input type="radio" value="yes" name="icecream">Yes</input>
        <input type="radio" value="no" name="icecream">no</input>
        <input type="radio" value="only strawberry" name="icecream">only strawberry</input>
        <input type="radio" value="only chocolate" name="icecream">only chocolate</input>

        You can then test the entries along the lines of:

        if($icecream==yes) {
        echo "Me, too!";
        } elseif($icecream==no) {
        echo "You don't know what you're missing!";
        } ...

        Hope this helps

        Norman 😃

          Hi Norman,

          I get your point.

          I realized that checkboxes cannot be used for my list as there can only be a single selection.

          Using the example you have provided,

          <input type="radio" value="yes" name="icecream">Yes</input>
          <input type="radio" value="no" name="icecream">no</input>
          <input type="radio" value="only strawberry" name="icecream">only strawberry</input>
          <input type="radio" value="only chocolate" name="icecream">only chocolate</input>

          The values which you have inserted is unique to itself, whereas i am using a variable, $a, that is pretty much on a global level, thus affecting all the other radio buttons, such that when my while loop executes, the radio button codes will look like tis i think...

          <input type="radio" value=$a name="icecream">Yes</input>
          <input type="radio" value=$a name="icecream">no</input>
          <input type="radio" value=$a name="icecream">only strawberry</input>
          <input type="radio" value=$a name="icecream">only chocolate</input>

          The value, $a, itself is ever-changing, according to the results taken from the while loop. My main concern is how to lock on the individual value for every new radio button generated and prevent the last result taken from the loop to overwrite all the other results drawn?

          Thank you for your time! 🙂

          Cheers
          t-bonist

            I've got the problem solved!

            Ok.. the mistake which I have commited is totally yucky n no one should ever commit it!

            Here's how....
            the variable $a, is constantly changing during the loop such that every new value drawn will over write the previous value. So no matter what, whenever I tried to call the value $a of each radio button, it will always be $a! The last drawn value! Duh....

            The catch here is not to call $a since it WILL only have a SINGLE value at any one time, rather, call for the NAME of the radio button group!!! Because a table of values is already created by the loop so all you just need to do is to call the radiogroup with your choice selected!

            A lesson to learn: be conscious of the values you are sending over to the next page. 🙂

            Thanks to Norman for the help rendered and also those who read thru these posts and worked their brains.

            Cheers
            t-bonist

              You got it. I made this mistake with my first attempt at a form - I didn't realize that you have to call the name of the radio button and then check the value - I was calling the value:

              if(yes==1) {
              echo "Me, too!";
              }

              Of course, I got absolutely nothing, not even an error message. I think this qualifies as a classic error.

              Norman

                Write a Reply...