Noctagon Posted October 3, 2006 Share Posted October 3, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
obsidian Posted October 3, 2006 Share Posted October 3, 2006 use the SUM() function:[code]SELECT SUM(colName) FROM tableName;[/code] Quote Link to comment Share on other sites More sharing options...
Hi I Am Timbo Posted October 3, 2006 Share Posted October 3, 2006 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. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted October 3, 2006 Share Posted October 3, 2006 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];} Quote Link to comment 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.