emma57573 Posted August 17, 2008 Share Posted August 17, 2008 I want to add up some totals from a mysql column and output them onto a php page. something like this $total=mysql_fetch_array(mysql_query("SELECT sum=+(total) as total FROM my_table WHERE seller_id=$seller_id")); echo $total; I know thats completely wrong! its just for examples sake. If someone could help me with the right syntax that would be great. Emma Quote Link to comment Share on other sites More sharing options...
php_dave Posted August 17, 2008 Share Posted August 17, 2008 You were not far off $result=mysql_query("SELECT sum(total) as total FROM my_table WHERE seller_id=$seller_id"); $total = mysql_fetch_array($result); echo $total; Quote Link to comment Share on other sites More sharing options...
emma57573 Posted August 17, 2008 Author Share Posted August 17, 2008 hum its still not working, the results are in decimals eg: 2.00, 4.00 etc Might that be the problem? Quote Link to comment Share on other sites More sharing options...
emma57573 Posted August 17, 2008 Author Share Posted August 17, 2008 Im getting 'Resource id #218' instead of the result Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 17, 2008 Share Posted August 17, 2008 Try echo mysql_error(); after executing query. Quote Link to comment Share on other sites More sharing options...
emma57573 Posted August 17, 2008 Author Share Posted August 17, 2008 ok not to worry Ive fixed it. Thanks for the help I used this: $result="SELECT sum(total) as total FROM my_table WHERE seller_id=".$seller_id; $php = mysql_query($result); if ($php) { $row = mysql_fetch_array($php); echo $row['total']; 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.