yjim Posted August 15, 2009 Share Posted August 15, 2009 how can i count the sum of downloads that is stored in several mysql rows i tried this: $query = mysql_query("SELECT downloads FROM items WHERE downloads != 0"); while ($row = mysql_fetch_array($query)) { echo $row['downloads']; } but it doesnt add all the rows together. Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/ Share on other sites More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 Your code does not do any form of counting. All you're telling it to do is to select all rows from the database where downloads is not equal to 0. Your then looping through the results. What where you expecting? Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899116 Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 SUM(downloads) as total Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899118 Share on other sites More sharing options...
yjim Posted August 15, 2009 Author Share Posted August 15, 2009 Your code does not do any form of counting. All you're telling it to do is to select all rows from the database where downloads is not equal to 0. Your then looping through the results. What where you expecting? idk its supposed to count the total number of downloads from all the items but its not working. can u fix it? Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899120 Share on other sites More sharing options...
yjim Posted August 15, 2009 Author Share Posted August 15, 2009 SUM(downloads) as total says call to undefined function Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899121 Share on other sites More sharing options...
wildteen88 Posted August 15, 2009 Share Posted August 15, 2009 SUM(downloads) as total says call to undefined function You're supposed to use it within your query. SUM is a MySQL function Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899124 Share on other sites More sharing options...
yjim Posted August 15, 2009 Author Share Posted August 15, 2009 ah that did it, thx. Link to comment https://forums.phpfreaks.com/topic/170450-solved-adding-with-php/#findComment-899125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.