Am doing this and getting a total for each row with php. But I need to actually insert the total into the table.
// Query table
$query = "SELECT * FROM $tablename";
$result = mysql_db_query ($db_name, $query, $link);
// Get total
$i = 0;
while ($Row = mysql_fetch_array ($result)) {
$PIDresult = mysql_query("SELECT C1+C2 as sum FROM $tablename");
$PIDtotal = mysql_result($PIDresult,$i,"sum");
// Faulty code here (listed seperately below)
$i++;
}
This calculates the correct total for each row. Omitted code to display in an html table for brevity, but so far this works fine.
Here is the faulty code I have in my while statement, just after $PIDtotal is calculated for each row....
$InsertTotal = "UPDATE $tablename SET C3='$PIDtotal'";
if (!mysql_query ($InsertTotal, $link) ) {
die (mysql_error());
}
Instead of inserting a different total for each row it seems to be inserting the total for the last row into each column.