The Sum Of All Rows: Use PHP or MySQL to Do The Math?
Firefox Wins Offline
Member
***
Posts: 164
Joined: Mar 2008
Post: #3
RE: The Sum Of All Rows: Use PHP or MySQL to Do The Math?
Well it works  Smile

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
<?php

// db connect
$sql = "SELECT sum( points ) FROM `mybb_users` ";
$result=mysql_query($sql) or die('Error query failed');

$row = mysql_fetch_array( $result );
echo $row[0];
mysql_close($link);

?>


A simple:  echo $result; doesn't work...
I wasn't expecting to use 'mysql_fetch_array' to finish off this time, but it does work. Is there a  better way to turn the "sum()" type of ( $result ) into a usable variable?

(This post was last modified: 09-25-2010 06:42 PM by Firefox Wins.)
09-25-2010 06:41 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
RE: The Sum Of All Rows: Use PHP or MySQL to Do The Math? - Firefox Wins - 09-25-2010 06:41 PM

 Standard Tools
Forum Jump: