Jump to content

While Loop Variable


rascle

Recommended Posts

Hi

i am have a load of numbers in a database and want to add them all together, so i have created a simple while loop that should add them all together, however i am not getting any results. Here is the code:

<?php

$totalgamespace = 0;
$rhysgamespace = mysql_query("SELECT * FROM 'games'");
while($gamespace = mysql_fetch_array($rhysgamespace)){
$rgamespace = $gamespace['size'];
$totalgamespace = $rgamespace + $totalgamespace;
}
echo $totalgamespace;


?>

 

Please help, thanks

Rhys

Link to comment
https://forums.phpfreaks.com/topic/198435-while-loop-variable/
Share on other sites

Your query is failing because the table name is enclosed in single-quotes, making it a string rather than a table name.

 

Once you fix that error, you do know that you can use the mysql SUM() function directly in your query to do this. No slow loop using parsed, tokenized, interpreted php code is needed.

Link to comment
https://forums.phpfreaks.com/topic/198435-while-loop-variable/#findComment-1041266
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.