ayok Posted December 31, 2007 Share Posted December 31, 2007 Hi, I have this table id total 1 34 1 32 1 45 2 64 2 54 etc. I want to sum the column total based on the id. So I made this mysql query. <?php $sum = ("SELECT SUM(total),id FROM list GROUP BY id") or DIE(mysql_error()); $total = mysql_fetch_array($sum); echo $total['sum(total)']; But I've got blank result. Could anybody tell me what's wrong? Thank you ayok Quote Link to comment https://forums.phpfreaks.com/topic/83838-solved-sum-doesnt-work/ Share on other sites More sharing options...
fataqui Posted December 31, 2007 Share Posted December 31, 2007 $total['sum(total)'] is not equal to $total['SUM(total)'] keys are CASE Sensitive Quote Link to comment https://forums.phpfreaks.com/topic/83838-solved-sum-doesnt-work/#findComment-426693 Share on other sites More sharing options...
ayok Posted December 31, 2007 Author Share Posted December 31, 2007 Thank you. I've changed sum with SUM. But it still doesn't work. ayok Quote Link to comment https://forums.phpfreaks.com/topic/83838-solved-sum-doesnt-work/#findComment-426702 Share on other sites More sharing options...
fenway Posted December 31, 2007 Share Posted December 31, 2007 Use a column alias. Quote Link to comment https://forums.phpfreaks.com/topic/83838-solved-sum-doesnt-work/#findComment-426924 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.