Page 1 of 1

cant get SUM to work with PHP

Posted: Sat Nov 13, 2004 4:58 pm
by ecaandrew
im trying to TOTAL up the "adminprofits" field in sql database and display it, but it wotn work

echo "<strong>Admin Profits:</strong> ";
$mysql_result = mysql_query("SELECT SUM(adminprofits) FROM sales");
echo "$mysql_result<br /><br />";

please help, thanks

Posted: Sat Nov 13, 2004 5:01 pm
by John Cartwright
What is being returned? Errors?

Posted: Sat Nov 13, 2004 5:03 pm
by ecaandrew
Admin Profits: Resource id #7

thats what i get back

Re: cant get SUM to work with PHP

Posted: Sat Nov 13, 2004 5:50 pm
by timvw
Any starting-php tutorial will have an example like this:

Code: Select all

$result = mysql_query('SELECT SUM(adminprofits) AS adminsales FROM sales');
$row = mysql_fetch_assoc($result);

echo $row['adminsales'];

Posted: Sat Nov 13, 2004 9:15 pm
by ecaandrew
thank you so much :)