sandrob57 Posted February 24, 2007 Share Posted February 24, 2007 Ill give you a scenario so you can understand what I am trying to do. Lets say I run a website, and on it you can have clubs. Each club members competes and earns points. I want to be able to select all the users from a certain club, and add their points cumulatively. So, if my database looked like this: ID Club Score 1fire14 2fire2 3ice8 4fire3 So, if I wanted the score of team fire, it would be 19. How do I get this in a variable??! I got to this so far, but it does not work: $a_ai = dbquery("SELECT SUM(score_field) FROM user_table WHERE team='".$team."'"); Help! Link to comment https://forums.phpfreaks.com/topic/39874-help-with-adding-colum-data/ Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 try this: $a_ai = dbquery("SELECT SUM(score_field) FROM user_table WHERE team='$team'"); Link to comment https://forums.phpfreaks.com/topic/39874-help-with-adding-colum-data/#findComment-192672 Share on other sites More sharing options...
sandrob57 Posted February 24, 2007 Author Share Posted February 24, 2007 I get "Resource id #37" as the variable output And, this is what it actually looks like. It is counting up the artificial intelligence of an alliance: c_ai is colony ai $a_ai = dbquery("SELECT SUM(c_ai) FROM fusion_users WHERE c_alliance='$a_choice'"); Link to comment https://forums.phpfreaks.com/topic/39874-help-with-adding-colum-data/#findComment-192674 Share on other sites More sharing options...
Archadian Posted February 24, 2007 Share Posted February 24, 2007 I can't see anything you are doing wrong. Check the MySQL database or whatever DB ur using for Resource id #37, i searched but couldn't find it Link to comment https://forums.phpfreaks.com/topic/39874-help-with-adding-colum-data/#findComment-192705 Share on other sites More sharing options...
sandrob57 Posted February 24, 2007 Author Share Posted February 24, 2007 I did this and it works: $result = dbquery("SELECT * FROM ".$db_prefix."users WHERE c_alliance='".$a_choice."'"); $ai = 0; while ($data = dbarray($result)) { $ai = $ai + $data['c_ai']; } Link to comment https://forums.phpfreaks.com/topic/39874-help-with-adding-colum-data/#findComment-192706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.