Jump to content

Archived

This topic is now archived and is closed to further replies.

Noctagon

How do I add up database entries

Recommended Posts

I am trying to run a query that will look at a specific table and then tally up the values in a certain field.

Cant figure out how to do this.

Any pointers would be greatly appreciated.

Thanks :)

Share this post


Link to post
Share on other sites
use the SUM() function:
[code]
SELECT SUM(colName) FROM tableName;
[/code]

Share this post


Link to post
Share on other sites
Another way which you may be more comfortable with, though it has far worse performance is to loop through the result set and add them with php.

Share this post


Link to post
Share on other sites
HUmmm Obsidian good call with mysql functions, I swear I always forget about mysql and how powerful it can be. Here is a php solution.

$sql = "SELECT myField FROM myDatabase WHERE myField = myClause ORDER BY myOrderBY";
$result = mysql_query($sql) OR die("Boom!");
while($row = mysql_fetch_array($result))
{
  $total += $row[0];
}

Share this post


Link to post
Share on other sites

×

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.