Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    8

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

    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

  2. #2
    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]"; 
    } 
    ?>

  3. #3
    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 16:32.

  4. #4
    Join Date
    Nov 2003
    Posts
    8
    Good point

    I'll alter the code,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •