jasonc Posted June 2, 2008 Share Posted June 2, 2008 I am having problems adding all numbers in a column, not a count rows but count the actual numbers in the whole column. this is what i have so far... thanks in advance for your help $count = mysql_query("SELECT count(numbers) from `info`"); Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/ Share on other sites More sharing options...
peranha Posted June 2, 2008 Share Posted June 2, 2008 $count = mysql_query("SELECT count(numbers) from `info`"); you want to use SUM $count = mysql_query("SELECT SUM(numbers) from `info`"); Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555257 Share on other sites More sharing options...
jasonc Posted June 2, 2008 Author Share Posted June 2, 2008 i changed to what you had but it did not work it shows an error about a resource id #6 i thought maybe i had not got the field set correctly but i think it is, it is set to int(11) Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555322 Share on other sites More sharing options...
jasonc Posted June 2, 2008 Author Share Posted June 2, 2008 the field is set to int(11) and not NULL and all have zeros in them. `numbers` int(11) NOT NULL default '0', Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555341 Share on other sites More sharing options...
PFMaBiSmAd Posted June 2, 2008 Share Posted June 2, 2008 To get help, you would need to post your code and post the actual error message. Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555372 Share on other sites More sharing options...
jasonc Posted June 2, 2008 Author Share Posted June 2, 2008 $count = mysql_query("SELECT count(numbers) from `info`"); you want to use SUM $count = mysql_query("SELECT SUM(numbers) from `info`"); i changed to what you had but it did not work it shows an error about a resource id #6 i thought maybe i had not got the field set correctly but i think it is, it is set to int(11) maybe it is this part which is wrong.... echo($count); Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555448 Share on other sites More sharing options...
fenway Posted June 2, 2008 Share Posted June 2, 2008 maybe it is this part which is wrong.... echo($count); That's right... you need to use mysql_result($count,0,0) to get the count itself. Link to comment https://forums.phpfreaks.com/topic/108304-count-up-all-numbers-in-a-column/#findComment-555513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.