0

How do I echo the latest values in column1? The below code echos the values before the update.

while($line = mysql_fetch_array($result)) {
$Student = $line["calss8"];

$querySf = "SELECT SUM(ABC) AS val1 FROM tbl1 WHERE student = '$Student'"; 
$resultSf = mysql_query($querySf); 
$rSf = mysql_fetch_array($resultSf); 
$totalSf = $rSf['val1']; 
$totTMonth = $totalSf;

mysql_query("UPDATE tbl4 SET column1 = $totTMonth WHERE student = '$Student' LIMIT 1");
}


echo $line["column1"].",,";
NathaliaZeed
  • 139
  • 4
  • 11

2 Answers2

0

As far as I know, you'll have to make a separate query to see what was just updated. I mean, run your select, perform your update, then do another select. You can get general information like how many rows were updated, but I don't think you can get specific information like the changed values in a column. Phil was right in suggesting that you should just print out the '$totTMonth' value since that is what you are updating your column with. That would be less overhead than doing another query to the database.

Quixrick
  • 3,190
  • 1
  • 14
  • 17
0

I think that problem starts before the code above. This code line will display the select results :echo $line["column1"].",,";. The variable $line is set before the code above. My solution is to do the following:

$result1 = mysql_query("SELECT column1 FROM student ..."); /* I insert the select query here */

While($row= mysql_fetch_array($result)) {

echo $row['column1'].",,";
} 
Mr. Radical
  • 1,847
  • 1
  • 19
  • 29