I am trying to figure out how to update MySQL table with array.
The Tables has 4 fields. REGNO, BATCHNO, NAMES and ATTEN_SUM. The REGNO has the unique value.
$i = 0;
while($row_recordset = mysql_fetch_array($query_run)) {
echo "<tr>";
echo " <td>{$row_recordset['REGNO']}</td>
<td>{$row_recordset['NAME']}</td>
<td><input type='text' name='atten_ave".$i."'></td>
";
echo "</tr>";
$i++;
Here's my html code for the previous page after the update page.
foreach($_POST as $textbox => $values) {
$query_update = "UPDATE `grades` SET `ATTEN_SUM` = '$values' WHERE `BATCHNO` = '$sessionbatch'";
if(mysql_query($query_update)) {
echo 'SUCCESS';
} else{
die(mysql_error());
}
}
$_POST is a array from dynamic inputs from the previous page. Here's the example of my output in the table.
REGNO | BATCHNO | NAME | ATTEN_SUM
====================================================
1 | ARPA 00-055 | Jason | 99
2 | ARPA 00-055 | Mark | 99
3 | ARPA 00-055 | Edgar | 99
It updates all the rows with the last value that I input.