SocomNegotiator Posted April 21, 2008 Share Posted April 21, 2008 Well I am trying to count all of one field in a table. There could be 50 or more rows with different credit amounts...well I want the sum of all of them together. I know this is probably pretty basic, but I can't figure it out. Here's what I have: $credit_total=mysql_query("SELECT COUNT(credit_amount) FROM credits"); $row = mysql_fetch_assoc($credit_total); $row['COUNT(credit_amount)'] = $count; Now $count for some reason is just showing up as nothing Any ideas? Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/ Share on other sites More sharing options...
zenag Posted April 21, 2008 Share Posted April 21, 2008 SELECT SUM(credit_amount) FROM credits Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522630 Share on other sites More sharing options...
SocomNegotiator Posted April 21, 2008 Author Share Posted April 21, 2008 So then you would call that by saying $row['SUM(credit_amount)'] or $row['credit_amount'] Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522631 Share on other sites More sharing options...
moon 111 Posted April 21, 2008 Share Posted April 21, 2008 Change the query to: SELECT SUM(credit_amount) AS credit_amount FROM credits and use $row['credit_amount']. Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522632 Share on other sites More sharing options...
zenag Posted April 21, 2008 Share Posted April 21, 2008 $row['SUM(credit_amount)'] Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522633 Share on other sites More sharing options...
SocomNegotiator Posted April 21, 2008 Author Share Posted April 21, 2008 That worked like a charm thank you very much!!!! Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522634 Share on other sites More sharing options...
SocomNegotiator Posted April 21, 2008 Author Share Posted April 21, 2008 SELECT SUM(credit_amount) AS credit_amount FROM credits That worked like a charm thank you very much!!!! Link to comment https://forums.phpfreaks.com/topic/102089-solved-need-help-with-phpmysql-count/#findComment-522635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.