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
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 :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.