I am created a system that lets the user upload data (student ids) to a database using a csv file. This works fine and uploads into the database. However, I want to be able to update the info in this database relating to each student id. I use this code to show the student id that were uploaded and to let the user check the boxes to update the student attendance: <?php $sql = mysql_query("SELECT * FROM ProgrammingFoundations"); while($row = mysql_fetch_array($sql)) { ?> <table align="center" border="1"> <tr> <td width="100"><input type="text" name="student_id" value=<?php echo $row['student_id'];?> size="10"></td> <td width="30"><input type="checkbox" name="lecture_1" size="1"></td> <td width="30"><input type="checkbox" name="lecture_2" size="1"></td> <td width="30"><input type="checkbox" name="lecture_3" size="1"></td> <td width="30"><input type="checkbox" name="lecture_4" size="1"></td> <td width="30"><input type="checkbox" name="lecture_5" size="1"></td> <td width="30"><input type="checkbox" name="lecture_6" size="1"></td> <td width="30"><input type="checkbox" name="lecture_7" size="1"></td> <td width="30"><input type="checkbox" name="lecture_8" size="1"></td> <td width="30"><input type="checkbox" name="lecture_9" size="1"></td> <td width="30"><input type="checkbox" name="lecture_10" size="1"></td> </tr> </table> I have used a loop so that it will show up for each student id that is in the database, however, obviously each field (for each loop) is the same so that the data for each student id is overwritten on the last loop. Can anyone help me so that i can update each of the student ids at the same time with different information ( e.g. different boxes/different number of boxes ticked). Thanks
<?php $sql = mysql_query("SELECT * FROM ProgrammingFoundations"); $i = 0; while($row = mysql_fetch_array($sql)) { ?> <table align="center" border="1"> <tr> <td width="100"><input type="text" name="data[<?php echo $i; ?>][student_id]" value=<?php echo $row['student_id'];?> size="10"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_1]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_2]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_3]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_4]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_5]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_6]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_7]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_8]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_9]" size="1"></td> <td width="30"><input type="checkbox" name="data[<?php echo $i; ?>][lecture_10]" size="1"></td> </tr> </table> <?php $i++; ?> Code (markup): I think this is what you mean? Every time it loop though, $i will add 1. Just look at the output of the html. Is this what you wanted?
Thank you, I was actually trying to do something like this but I wasnt sure how to add it to the name? I was putting it after "lecture" but i just put the variable there. I'll be sure to try this tomorrow but yes this was the type of thing I was looking for.
Ok. If you call print_r($_POST) after you submit the data, you will see how the data is structured so you can handle it accordingly. You might want to use the studentID for the $i, assuming the student ID is unique
I got this : Array ( [data] => Array ( [0] => Array ( [student_id] => 200727669 ) [1] => Array ( [student_id] => 200727668 ) [2] => Array ( [student_id] => 200712312 ) [3] => Array ( [student_id] => 200755922 ) [4] => Array ( [student_id] => 200812345 ) [5] => Array ( [student_id] => 200828765 ) [6] => Array ( [student_id] => 200812345 ) ) ) Code (markup): when I used print_r($_POST); How do I get each of these into seperate variables and the results of each lecture (checkbox)into seperate variables?