counting all values in column without creating a new column

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smudly
Forum Commoner
Posts: 71
Joined: Wed Jun 09, 2010 10:09 pm

counting all values in column without creating a new column

Post by Smudly »

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?
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: counting all values in column without creating a new col

Post by Sephern »

Smudly wrote: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?
1. Select the value of the relevant columns in your database, and retrieve them as an array in your site
2. Declare a variable ($total_downloads?)
3. Foreach loop through the array, adding each of the records onto the variable

The variable would contain the total downloads amount.

Why would you not want to just create a record with that information in though?
Post Reply