If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > variables in mysql query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-24-03, 02:21
deRusett deRusett is offline
Registered User
 
Join Date: Nov 2003
Posts: 8
variables in mysql query

this is a sample code of what I am doing


Code:
<?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 works great, prints exactly what I want on the screen


BUT, I want to make the
Code:
WHERE c.id = 1 AND m.clan = 1
not constant. I need it to be a variable since there are many clans

I tried this
Code:
WHERE c.id =$clan[id] AND m.clan =$clan[id]
but every time I put any sort of variable inplace of the constant I get this error

Quote:
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
anyone have any ideas?

if some one thinks they might have the knowledge to help I can share with them the actuall source code, which as you can see is a few hundred lines.

thanks for any help that can be given
Reply With Quote
  #2 (permalink)  
Old 11-24-03, 03:19
deRusett deRusett is offline
Registered User
 
Join Date: Nov 2003
Posts: 8
seems I jumped the gun posting here

my fix is this

Code:
<?php 
mysql_pconnect("*****","*****","*******"); 
mysql_select_db("Clan"); 

$Tstrength = mysql_query("SELECT m.clan, SUM(m.strength) FROM 
members m, clan c  WHERE c.id =" . clan[id] . " AND m.clan = " .  clan[id]
 . " Group By m.strength"); 

while ($row = mysql_fetch_array($Tstrength)) 
{ 
print" Strength:  $row[1]"; 
} 
?>
Reply With Quote
  #3 (permalink)  
Old 11-27-03, 15:30
khibinite khibinite is offline
Registered User
 
Join Date: Oct 2003
Posts: 63
In any case you should point array items as $clan[$id] (I suppose you perform it in any loop)

Code:

<?php 
mysql_pconnect("*****","*****","*******"); 
mysql_select_db("Clan"); 

$Tstrength = mysql_query("SELECT m.clan, SUM(m.strength) FROM 
members m, clan c  WHERE c.id =".$clan[$id]." AND m.clan = ".$clan[$id]
 . " Group By m.strength"); 

while ($row = mysql_fetch_array($Tstrength)) 
{ 
print" Strength:  $row[1]"; 
} 
?>
 

Last edited by khibinite; 11-27-03 at 15:32.
Reply With Quote
  #4 (permalink)  
Old 11-28-03, 00:07
deRusett deRusett is offline
Registered User
 
Join Date: Nov 2003
Posts: 8
Good point

I'll alter the code,
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On