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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
smerny Posted August 15, 2009 Share Posted August 15, 2009 SUM(downloads) as total Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
yjim Posted August 15, 2009 Author Share Posted August 15, 2009 ah that did it, thx. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.