Nested Loops

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Nested Loops

Post by guymclaren »

Code: Select all

 
 
$sqlq="SELECT * FROM depts";
$objRS = mysql_query($sqlq);
  
    while($row = mysql_fetch_array($objRS, MYSQL_ASSOC)) {
        echo "<tr><td width=155><img src=images/{$row['image']} width=150 height=100></td><td width 425><table width=425><tr><td>{$row['Name']}</td><td align=right>{$row['CODE']}</td></tr><tr><td colspan=2>{$row['description']}";
 
        $sqlc="SELECT * FROM cats WHERE dept={$row['CODE']} ";
        $objRSc = mysql_query($sqlc);
            while($rowa = mysql_fetch_array($objRSc, MYSQL_ASSOC)){
                echo "{$rowa['name']"." ";} //line 32
                
        echo "</td></tr></table></td></tr>";
}
The logic above makes sense to me but does not work, Who wants to tell me why I am being stupid?

The result is as follows.
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '}' in /var/www/vhosts/laeveldbou.co.za/httpdocs/catalogue/index.php on line 32
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Nested Loops

Post by papa »

$sqlc="SELECT * FROM cats WHERE dept= ".$row['CODE'];

Is the first thing I see.
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Re: Nested Loops

Post by guymclaren »

No thats not the problem..... It has to do with the nesting. I am busy trying to see exactly where it breaks.commenting each line.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Nested Loops

Post by papa »

You are not closing your second while loop.
guymclaren
Forum Newbie
Posts: 11
Joined: Tue Feb 17, 2009 10:53 pm

Re: Nested Loops

Post by guymclaren »

Thanks, That was one of the errors. the other was here

Code: Select all

$sqlc="SELECT * FROM cats WHERE dept= '".$row['CODE']."'";
Post Reply