Jump to content

adding column contents


deRusett

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

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/
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

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/#findComment-4513
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

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/#findComment-4514
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,

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/#findComment-4518
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];

}

?> 

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/#findComment-4521
Share on other sites

  • 2 weeks later...

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

Link to comment
https://forums.phpfreaks.com/topic/1361-adding-column-contents/#findComment-4696
Share on other sites

Archived

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

×
×
  • Create New...

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.