Click here to Skip to main content
15,908,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

I want to sum up the values returned by the $row['val'] that you can see in my code snippet below:

PHP
/*
this part contains the connection parameters
*/

$query = "SELECT val FROM table";
$result = mysql_query($query);

/*
this makes sure the result contains data
*/

WHILE($row = mysql_fetch_assoc($result)){
      echo $row['val'];
}


Thank you in advance.
Posted
Updated 10-Aug-12 1:06am
v2
Comments
Baba_Dee 10-Aug-12 7:18am    
Thank you very much, the solution worked
Thanks a lot.

PHP
$yournumber = $yournumber + $row['val'];


If I'm not missing any evident thing, this should do it.
 
Share this answer
 
Comments
Baba_Dee 10-Aug-12 7:24am    
Your Solution worked, Thanks a lot.
Joan M 10-Aug-12 9:18am    
Thank you for your comment and for evaluating the answer.
I'm glad it has helped you. ;)
anyvariable = echo $row["SUM(val)"];

It will work if i am rite..
 
Share this answer
 
Comments
Joan M 10-Aug-12 7:50am    
This can't work as the OP is asking for adding all the values returned from the loop. This is only giving you the last value in the loop inside anyvariable... Apart of that the variable itself should start with a $ sign...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900