cant get SUM to work with PHP

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
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

cant get SUM to work with PHP

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What is being returned? Errors?
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

Admin Profits: Resource id #7

thats what i get back
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Re: cant get SUM to work with PHP

Post 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'];
ecaandrew
Forum Commoner
Posts: 72
Joined: Fri Nov 12, 2004 5:05 pm

Post by ecaandrew »

thank you so much :)
Post Reply