So i have this code to update a table in my database. $C1
, $C2
, etc. are a set of array from previous calculation :
$Cupdate = array($C1, $C2, $C3, $C4, $C5, $C6);
array_unshift($Cupdate, null);
$Cfinalupdate = call_user_func_array('array_map', $Cupdate);
if(is_array($Cfinalupdate)){
$valuesArr = array();
foreach($Cfinalupdate as $row){
$sqlup = "UPDATE tempselect SET ";
$C1up = mysql_real_escape_string( $row['0'] );
$C2up = mysql_real_escape_string( $row['1'] );
$C3up = mysql_real_escape_string( $row['2'] );
$C4up = mysql_real_escape_string( $row['3'] );
$C5up = mysql_real_escape_string( $row['4'] );
$C6up = mysql_real_escape_string( $row['5'] );
$valuesArr[] = "C1 = '$C1up', C2 = '$C2up', C3 = '$C3up', C4 = '$C4up', C5 = '$C5up', C6 = '$C6up'";
$sqlup .= implode(',', $valuesArr);
mysql_query($sqlup) or exit(mysql_error());
}
}
But code above only put the last row of $Cfinalupdate
, suppose i want to update my database become like this :
C1 C2 C3 C4 C5 C6
1 4 2 3 1 5
6 2 4 1 2 7
8 1 2 5 4 6
But it turns out like this when i see in my database table :
C1 C2 C3 C4 C5 C6
8 1 2 5 4 6
8 1 2 5 4 6
8 1 2 5 4 6
I've tried this code to INSERT
a set of array into database, but it works perfectly, but why it only update with the last row of the array? thank you.