Smudly Posted August 12, 2010 Share Posted August 12, 2010 Hi, I have downloads that are available for users. They can click the links to download the file. Once they do this, I have a query that updates the number of downloads that file has received. I need to create a query that adds up all the rows Total Downloads. So for example: i have 3 rows: Name - Total Downloads First - 2 Second - 23 Third - 7 Using the query for these rows would give me an amount of 32. Any idea how to do this? I don't want to have to create a new column to find the total number of downloads. Any other ways? Quote Link to comment https://forums.phpfreaks.com/topic/210578-counting-all-values-in-column-without-creating-a-new-columnhi-i-have-downloads/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 12, 2010 Share Posted August 12, 2010 http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_sum Quote Link to comment https://forums.phpfreaks.com/topic/210578-counting-all-values-in-column-without-creating-a-new-columnhi-i-have-downloads/#findComment-1098617 Share on other sites More sharing options...
Smudly Posted August 12, 2010 Author Share Posted August 12, 2010 Alright, I've been trying that and not getting the right results. Here is the code I'm using. $downloadscount = mysql_query("SELECT SUM(timesdownloaded) FROM sheets WHERE timesdownloaded>='0'"); $totaldownloads = mysql_num_rows($downloadscount); My sql table looks like: id int(11) No artist varchar(50) No title varchar(50) No url varchar(2083) No timesdownloaded int(11) No lastdownloaded date No date date No Right now I have 20 rows in there. Most are set to 0, but five have a value of at least 1 thanks Quote Link to comment https://forums.phpfreaks.com/topic/210578-counting-all-values-in-column-without-creating-a-new-columnhi-i-have-downloads/#findComment-1098618 Share on other sites More sharing options...
sasa Posted August 13, 2010 Share Posted August 13, 2010 try <?php $downloadscount = mysql_query("SELECT SUM(timesdownloaded) FROM sheets WHERE timesdownloaded>='0'"); //$totaldownloads = mysql_num_rows($downloadscount); $totaldownloads = mysql_result($downloadscount, 0, 0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/210578-counting-all-values-in-column-without-creating-a-new-columnhi-i-have-downloads/#findComment-1098764 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.