deRusett Posted November 14, 2003 Share Posted November 14, 2003 Hello I\'m sorry if this question seems \"noobish\" but I can\'t figure it out I have 2 tables we will call them table1 and table2 I use this query SELECT 1.blah, 2.id, 1.number FROM table1 1, table2 2 WHERE 2.id = "X" AND 1.blah = "X" ------------------------ id - blah - number ---------------------- X - X - 3.00 X - X - 4.00 X - X - 7.00 X - X - 4.00 I would like to add all of the numbers to give me one value I can use can anyone help? thank you Quote Link to comment Share on other sites More sharing options...
Barand Posted November 14, 2003 Share Posted November 14, 2003 SELECT 1.blah, SUM(1.number ) FROM table1 1, table2 2 WHERE 2.id = 1.blah ### you need a join condition if more than 1 table AND 1.blah = \"X\" Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 14, 2003 Author Share Posted November 14, 2003 I get this error when using your query #1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is illegal if there is no GROUP BY clause this is the exact query I used SELECT m.clan, SUM(m.strength) FROM members m, clan c WHERE c.id = "1" AND m.clan = "1" when the I get this working for c.id = 1 and m.clan = 1 then both of the 1\'s become variables, since there are multiple clans and multiple members Quote Link to comment Share on other sites More sharing options...
Barand Posted November 14, 2003 Share Posted November 14, 2003 Soory about missing the group by. This will give total for blah = X SELECT 1.blah, SUM(1.number ) FROM table1 1, table2 2 WHERE 2.id = 1.blah AND 1.blah = \"X\" GROUP BY 1.blah and this gives totals for all blahs SELECT 1.blah, SUM(1.number ) FROM table1 1, table2 2 WHERE 2.id = 1.blah GROUP BY 1.blah Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 14, 2003 Author Share Posted November 14, 2003 thanks, in PHPmyAdmin it out puts what I want to see SELECT m.clan, SUM(m.strength) FROM members m, clan c WHERE c.id = "1" AND m.clan = "1" Group By m.strength I made a php page in hopes to output m.strength but it didn\'t do it <?php mysql_pconnect("*****","*****","*******"); mysql_select_db("Clan"); $Tstrength = mysql_query("SELECT m.clan, SUM(m.strength) FROM members m, clan c WHERE c.id = "1" AND m.clan = "1" Group By m.strength"); print "$Tstrength"; ?> this does not out put a number it outputs Resource id #3 which really confuses me since no members have an ID of 3, Quote Link to comment Share on other sites More sharing options...
shivabharat Posted November 14, 2003 Share Posted November 14, 2003 Humm!! Resource ID is something which the mysql_query. See the manual for more details. <?php mysql_pconnect("*****","*****","*******"); mysql_select_db("Clan"); $Tstrength = mysql_query("SELECT m.clan, SUM(m.strength) FROM members m, clan c WHERE c.id = "1" AND m.clan = "1" Group By m.strength"); while ($row = mysql_fetch_array($Tstrength)) { echo $row[0]; echo $row[1]; } ?> Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 14, 2003 Author Share Posted November 14, 2003 Thanks works, though I only need echo $row[1] echo $row[0] makes it out put a number that I can\'t figure out were it came from, I must say you guys opened a can of worms being so fast and friendly, now you are stuck with me Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 24, 2003 Author Share Posted November 24, 2003 <?php mysql_pconnect("*****","*****","*******"); mysql_select_db("Clan"); $Tstrength = mysql_query("SELECT m.clan, SUM(m.strength) FROM members m, clan c WHERE c.id = 1 AND m.clan = 1 Group By m.strength"); while ($row = mysql_fetch_array($Tstrength)) { print" Strength: $row[1]"; } ?> this code works great if c.id and m.clan are numbers, but I need them to be a variable I tried WHERE c.id =$clan[id] AND m.clan =$clan[id] but I get Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site55/fst/var/www/html/game/clan.php on line 163 any ideas? what I need is to beable to see the users clan[id]\'s to determin the strength of said clan the site uses sessions, if some one is truely interested in troubleshooting with me beyond forum posts I\'ll show the enite source code to you give you a better understanding of what I\'m trying to do Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 24, 2003 Author Share Posted November 24, 2003 some glitch caused me to multi post sorry Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 24, 2003 Author Share Posted November 24, 2003 as said above the glitch was telling me \"failed send email\" and did not tell me it had posted this forum seems to have an probelm I posted on Nov 24 and it still says Nov 14 as the last post Quote Link to comment Share on other sites More sharing options...
deRusett Posted November 24, 2003 Author Share Posted November 24, 2003 bumping as a test Quote Link to comment 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.