Jump to content

counting all values in column without creating a new columnHi, I have downloads


Smudly

Recommended Posts

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?

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

try

<?php
$downloadscount = mysql_query("SELECT SUM(timesdownloaded) FROM sheets WHERE timesdownloaded>='0'");
//$totaldownloads = mysql_num_rows($downloadscount);
$totaldownloads = mysql_result($downloadscount, 0, 0);
?>

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.