Subpages not showing up

Hi there,

I have built a menu using CSS, PHP, and javascript. Here is the PHP code below. I am trying to figure out why the sub-sub pages won’t show up. The sub category shows up, but not the pages that belong to it.

If I exchange the WHERE subid={$subcat[id]} and make it WHERE subid=1, then it shows up. But otherwise, it isn’t recognizing the “id” of the sub category.


	# Connect to the database 

// Get the categories 
$cat_result = mysql_query('SELECT catid, category FROM category;'); 

// Loop through the categories 
while ($category = mysql_fetch_assoc($cat_result)) 
{ 
    echo "<li><a href='javascript:blankfunction()'>{$category[category]}</a><ul>"; 

    // Category Pages Loop    
    $page_result = mysql_query("SELECT id, title FROM pages WHERE catid={$category[catid]};"); 
     
    while ($page = mysql_fetch_assoc($page_result)) 
    { 
        echo "<li><a href='sidepage.php?id={$page[id]}'>{$page[title]}</a></li>";
	}
	//Sub-category loop
	$subcat_result = mysql_query("SELECT id, catid, subcat FROM subcat WHERE catid={$category[catid]};");

	while ($subcat = mysql_fetch_assoc($subcat_result))  
    {  
    echo "<li><a href='javascript:blankfunction()'>{$subcat[subcat]}</a><ul>";  
    } 
    // Sub-category page loop 
    $subpage_result = mysql_query("SELECT id, subid, title FROM subpages WHERE subid={$subcat[id]};");  
      
    while ($subpage = mysql_fetch_assoc($subpage_result))  
    {  
        echo "<li><a href='sidepage.php?id={$subpage[id]}'>{$subpage[title]}</a></li>"; 

    }  
    echo "</ul></li>"; 
}  
 

Thanks way in advance!