Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button loop

Status
Not open for further replies.

mrobinson

MIS
Oct 11, 2002
36
GB
I have created a php form and am displaying some html which includes radio buttons. The form takes information from a database then displays it in a list in the form and in the while loop that does this it displays radio buttons next to each data item. I can get this to disply everything ok but im not sure how i would go about naming each radio button differently within the loop so they can be called on the following form individually. could someone please advise me on the best approach for this.

In the next form i also need to read these values in one at a time for each record, is the best way to do this with another while loop?

thanks
 
i am using radio buttons as it is either or, does that sound the best way to go about it?
 
I'm not really sure what you're trying to do, but maybe this example will give you some ideas

If the user is presented with the following HTML page:
Code:
<html><body><form action="show_post.php" method="post">
<table border="1">
<tr><td>group 1<br>(select 1)</td><td>group 2<br>(select 1)</td><td>group 3<br>(select many)</td></tr>
<tr><td>
<input type="radio" name="radio[1]" value="r1">selection 1<br>
<input type="radio" name="radio[1]" value="r2">selection 2<br>
<input type="radio" name="radio[1]" value="r3">selection 3<br>
<input type="radio" name="radio[1]" value="r4">selection 4<br>
<input type="radio" name="radio[1]" value="r5">selection 5<br>
<input type="radio" name="radio[1]" value="r6">selection 6<br>
</td><td>
<input type="radio" name="radio[2]" value="rA">selection A<br>
<input type="radio" name="radio[2]" value="rB">selection B<br>
<input type="radio" name="radio[2]" value="rC">selection C<br>
<input type="radio" name="radio[2]" value="rD">selection D<br>
<input type="radio" name="radio[2]" value="rE">selection E<br>
<input type="radio" name="radio[2]" value="rA">selection F<br>
</td><td>
<input type="checkbox" name="check[3]" value="cA">selection A<br>
<input type="checkbox" name="check[3]" value="cB">selection B<br>
<input type="checkbox" name="check[3]" value="cC">selection C<br>
<input type="checkbox" name="check[3]" value="cD">selection D<br>
<input type="checkbox" name="check[3]" value="cE">selection E<br>
<input type="checkbox" name="check[3]" value="cF">selection F<br>
</td><tr></table>
<input type="submit"></form></body></html>

When the user selects his one radiobutton from group 1, one radiobutton from group 2, and multiple radiobuttons from group 3 and submits the form, in the script to which the form submits, $_POST will look something like:

Code:
Array
(
    [radio] => Array
        (
            [1] => r4
            [2] => rB
        )

    [check] => Array
        (
            [3] => cE
        )

)


The trick is the naming of the inputs. By creating the names of the inputs as PHP array references, PHP populates $_POST as though the inputs are an array.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i am trying to create a basic attendance system that when an office number is selected it selects all employees from that office to the screen from the database. Besides each name i want a 2 radio buttons to select if the employee is absent or not and then in the following form to add this information to a table in the database. I have created the form using while loops and it outputs all the names with the radio buttons, done in a while loop. However i am struggerling with how each radio two radio buttons can be identified individually to each employee. do i need to use some sort of loop so that each value is different ie. each time the loop goes round it increments the radio box name by 1?

Sorry i was not so clear in my original explanation. thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top