Jump to content

php foreach with radio buttons?


shortysbest

Recommended Posts

I'm not sure how to use foreach to send multiple form information to the database.

 

<form>
<input id="<?php print $row['id'];?>" name="attendance" type="radio" value="1" checked="checked" />
<input id="<?php print $row['id'];?>" name="attendance" type="radio" value="2" />
<input id="<?php print $row['id'];?>" name="attendance" type="radio" value="3" />
</form>

 

I have a group of 3 buttons for three different options and this is in a php while loop,and there could be anywhere from 1 to 30 of these forms that ineed to send the data to the database at the same time.

each one of these groups are next to a user to mark if they were present, tardy, or absent.

I need it to get the id of the user for each one of these and send the value to the database as well.

 

Link to comment
https://forums.phpfreaks.com/topic/214379-php-foreach-with-radio-buttons/
Share on other sites

Your values should be retrieved from an array atleast that's  what the foreach loop is for.

You might try it with a while loop when you retrieve data from you database: like :

 

<form action="#" method="postal_pigeon">
<?php $result = mysqli_query($dbc,$query)or die(mysqli_error($dbc).mysqli_errno($dbc));
                while ($row = mysqli_fetch_array($result)){
                   echo '<input id="'.$row['id'].'>" name="attendance" type="radio" value="'.$row['value'].'" />';
                } 
?>
</form>

 

- I made some changes :)

change form to

<input id="<?php print $row['id'];?>" name="attendance[<?php print $row['id'];?>]" type="radio" value="1" checked="checked" />
<input id="<?php print $row['id'];?>" name="attendance[<?php print $row['id'];?>]" type="radio" value="2" />
<input id="<?php print $row['id'];?>" name="attendance[<?php print $row['id'];?>]" type="radio" value="3" />

all in one forrm

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.