onlyican Posted August 9, 2006 Share Posted August 9, 2006 HeyMy brain is dead today, I had too much sleep last night, I hit 5 hours. (This is a lot to me)AnywayI have a Mysql TableIn that table I have a field called amount, which is a doubleand a field called aff, which is a number not unique, but refers to the id_num of the affiliatesAnywayI am running a query to find out who is owed money, and how muchThis is wha I have so far$query2 = "SELECT * FROM sales WHERE paid = 'n' GROUP BY aff";The problem is this only gives me one value from the amount, it is not adding them upI can run another query$total_amount = "SELECT SUM(amount) FROM sales WHERE paid = 'n' AND aff = '".$row2["aff"]."'";But is there a better way to do all thisI am thinking off the amount of queries that might run on one page Quote Link to comment https://forums.phpfreaks.com/topic/17014-sum-of-values-in-php/ Share on other sites More sharing options...
sasa Posted August 9, 2006 Share Posted August 9, 2006 try[code]$total_amount = "SELECT SUM(amount) FROM sales WHERE paid = 'n' GROUP BY aff";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/17014-sum-of-values-in-php/#findComment-71836 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Author Share Posted August 9, 2006 mm, simular to what I posted and did not want to useAnyway I am using it, it works out best for the rest of the codethanx Quote Link to comment https://forums.phpfreaks.com/topic/17014-sum-of-values-in-php/#findComment-71846 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.