I am trying to figure out how to update mysql table with array.
The table has 3 fields: id, rate, pol_id. The "insert into" works perfect:
foreach ($rates as $rn=>$rv) {
$sql3=mysql_query("INSERT into `rates` (`rate`, `pol_id`)
values ( '$rv', '$polid',)") or die ("Unable to issue query sql2: ".mysql_error()); }
$rates is actually array from dynamic input fields.
So I get something like this example:
id | rate | pol_id
=========================
1 | 5.6 | 272
2 | 6.3 | 272
3 | 7.9 | 272
Now I would like to edit the values in the input fields so I need to update the table:
I have tried this:
foreach ($rates as $rn=>$rv) {
$sql3=mysql_query("UPDATE `rates` SET `rate`='$rv' WHERE `pol_id`='$polid'")or die ("Unable to issue query sql3: ".mysql_error()); }
But this isn't working, it updates all the rows with the last value.
Can ypu please help me with this?