StanLytle Posted May 27, 2007 Share Posted May 27, 2007 I'm trying to add the values of a column called 'Views" and output the result. This is what I have, but it does not work. What am I doing wrong? $sql_query = "SELECT SUM(Views) AS TotalViews FROM Photos"; $result = mysql_query($sql_query); $num = mysql_num_rows($result); $TotalViews=number_format($num); echo "$TotalViews"; Thanks, Stan Link to comment https://forums.phpfreaks.com/topic/53193-solved-need-help-with-sum-function/ Share on other sites More sharing options...
Barand Posted May 27, 2007 Share Posted May 27, 2007 You need to get the value from the resultset $totalViews = mysql_result($result, 0, 'TotalViews') Link to comment https://forums.phpfreaks.com/topic/53193-solved-need-help-with-sum-function/#findComment-262870 Share on other sites More sharing options...
StanLytle Posted May 28, 2007 Author Share Posted May 28, 2007 That did the trick. Thanks. Stan Link to comment https://forums.phpfreaks.com/topic/53193-solved-need-help-with-sum-function/#findComment-262966 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.