dannybrazil Posted January 23, 2010 Share Posted January 23, 2010 Hello I have this : $q = "SELECT SUM(total) FROM account"; now I want to echo the sum() on the screen, how do I do that ? $q=mysql_query($q); echo $q; ? Quote Link to comment https://forums.phpfreaks.com/topic/189549-echo-sum-problem/ Share on other sites More sharing options...
wildteen88 Posted January 23, 2010 Share Posted January 23, 2010 To get your results from your query you need to use ond of the mysql_fetch_* functions, such as mysql_fetch_assoc. This function will return each row as an associative array $query = "SELECT SUM(total) FROM account"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['SUM(total)']; } Quote Link to comment https://forums.phpfreaks.com/topic/189549-echo-sum-problem/#findComment-1000504 Share on other sites More sharing options...
Andy-H Posted January 23, 2010 Share Posted January 23, 2010 You can also use MySQL Aliases like so: $query = "SELECT SUM(total) AS sumTotal FROM account"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { echo $row['sumTotal']; } Quote Link to comment https://forums.phpfreaks.com/topic/189549-echo-sum-problem/#findComment-1000538 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.