mattm1712 Posted December 12, 2010 Share Posted December 12, 2010 this is my coding can anyone see what is wrong with it? $total = mysql_query("SELECT * FROM comments WHERE id=0"); $temp=0; while ($array=mysgl_fetch_assoc($total)) { $temp+=$array[clicks]; } echo "$total Clicks\n"; Quote Link to comment https://forums.phpfreaks.com/topic/221405-sum-of-values-in-database-help/ Share on other sites More sharing options...
BlueSkyIS Posted December 12, 2010 Share Posted December 12, 2010 echo "$temp Clicks\n"; Quote Link to comment https://forums.phpfreaks.com/topic/221405-sum-of-values-in-database-help/#findComment-1146228 Share on other sites More sharing options...
Yesideez Posted December 12, 2010 Share Posted December 12, 2010 Without any type of help regarding what it is you want to achieve it's pretty difficult but if your "id" field is set to AUTO_INCREMENT then it might not return anythign as AI starts counting at 1 and never 0. If you want to return the total you can use this instead: $total = mysql_query("SELECT COUNT(*) AS total FROM comments WHERE id=0"); $row=mysgl_fetch_assoc($total); echo $row['total']." Clicks\n"; If you're not wanting the SUM() then try TOTAL() but not sure entire what it is you're wanting to do. Quote Link to comment https://forums.phpfreaks.com/topic/221405-sum-of-values-in-database-help/#findComment-1146230 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.