Jump to content

Archived

This topic is now archived and is closed to further replies.

deRusett

adding column contents

Recommended Posts

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

Share this post


Link to post
Share on other sites

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\"

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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,

Share this post


Link to post
Share on other sites

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];

}

?> 

Share this post


Link to post
Share on other sites

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 :P

Share this post


Link to post
Share on other sites

<?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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.