nested while loop with mysql queries

Discussion in 'PHP' started by mintuz, Nov 20, 2010.

  1. #1
    $sql="SELECT * FROM countries"; 
    $result=mysql_query($sql); 
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
            { 
                $ccode = $row["ccode"]; 
                echo '<h1>'.$row["country"].'</h1>'; 
                 
                sql2="SELECT * FROM `numbers` WHERE `location` = '".$ccode."'"; 
                $result2=mysql_query($sql2); 
                    while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC)) 
                        { 
                            echo '<table><tr>'; 
                            echo '<td><p>'.$row["name"].'</p></td><td><a href="http://'.$row2["url"].'">'.$row2["url"].'</a></td>'; 
                            echo '</tr></table>';     
                        } 
            }  
    PHP:
    getting an error for the line

    sql2="SELECT * FROM `numbers` WHERE `location` = '".$ccode."'"; 
    PHP:
    any suggestions. the error says Parse error: parse error in C:\wamp\www\prototype1\index.php on line 42

    I basically trying to make a script which will group url's depending on the country origin which is inputted by user.

    I have tried the string without the ` around the field names of the table. any other suggestions.
     
    Last edited: Nov 20, 2010
    mintuz, Nov 20, 2010 IP
  2. mikecampbell

    mikecampbell Peon

    Messages:
    26
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    All PHP variables need a $ before them. On that line sql2 does not have a $.
     
    mikecampbell, Nov 20, 2010 IP
  3. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    mikecampbell has it. ;)
     
    w47w47, Nov 22, 2010 IP