I have table, from this table, I want to do some math operation (such as sum) then I want to save the result in a separate column from the table.
so this is my table
table: xxx
! code ! A ! B ! C !
---------------------------------
! 0001 ! 4 ! 2 ! !
! 0002 ! 2 ! 1 ! !
! 0003 ! 1 ! 4 ! !
! 0004 ! 3 ! 5 ! !
then I use this code to call the query, and save the math operation.
$mySql = "SELECT * FROM xxx ORDER BY code ASC ";
$myQry = mysql_query($mySql, $koneksidb) or die ("Query salah : ".mysql_error());
while ($myData = mysql_fetch_array($myQry))
$sum = $myData['A'] + $myData['A']
$mySql = "UPDATE xxx SET C='$sum' WHERE code='$Kode'";
$myQry = mysql_query($mySql, $koneksidb) or die ("Gagal query".mysql_error());
while ($myData = mysql_fetch_array($myQry))
{
$Kode = $myData['code'];
}
my problem is, it's not come up like what I want. I want like this:
table: xxx
! code ! A ! B ! C !
---------------------------------
! 0001 ! 4 ! 2 ! 6 !
! 0002 ! 2 ! 1 ! 3 !
! 0003 ! 1 ! 4 ! 5 !
! 0004 ! 3 ! 5 ! 8 !
but this is what I've got
table: xxx
! code ! A ! B ! C !
---------------------------------
! 0001 ! 4 ! 2 ! 6 !
! 0002 ! 2 ! 1 ! 6 !
! 0003 ! 1 ! 4 ! 6 !
! 0004 ! 3 ! 5 ! 6 !
any help? I think, my code just take data from the first code, how can I fix this?