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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

try

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.