Page 1 of 1

Nested Loops

Posted: Thu Mar 19, 2009 6:50 am
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

Re: Nested Loops

Posted: Thu Mar 19, 2009 7:08 am
by papa
$sqlc="SELECT * FROM cats WHERE dept= ".$row['CODE'];

Is the first thing I see.

Re: Nested Loops

Posted: Thu Mar 19, 2009 7:15 am
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.

Re: Nested Loops

Posted: Thu Mar 19, 2009 7:18 am
by papa
You are not closing your second while loop.

Re: Nested Loops

Posted: Thu Mar 19, 2009 7:44 am
by guymclaren
Thanks, That was one of the errors. the other was here

Code: Select all

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