Ciao a tutti,
sto cercando di riempire una select con delle categorie e sottocategorie prese dal database.
Le tabelle sono strutturate nel seguente modo

cat id, nomeCat
sottoCat id, id_cat ,sottoCat

e il codice che sto utilizzando per visualizzare la select è il seguente.
Codice PHP:
$sqlQuery "SELECT categorie FROM xxx ";
$rsQuery mysql_query($sqlQuery) or die(mysql_error());

<
select name='padreCat'  >
echo 
"<option></option>";
    while(
$rows mysql_fetch_array($rsQuery)){
        
$id $rows['id'];
        
$Cat $rows['categorie'];
        echo 
"<optgroup label='$Cat'>$Cat";
               
// cerco le sottocategorie
               
$sql "SELECT * FROM xxx WHERE id_cat = ".$id." ";
               
$rs mysql_query($sql) or die(mysql_error());
               
$max mysql_num_rows($rs);
               if(
$max!=0){
                 for(
$j=0;$j<$max;$j++){
                       
$rg mysql_fetch_assoc($rs);
                        
$sottoCat $riga['sottoCat'];
                        
$iId $riga['iId'];
                   echo 
"<option value='$iId'>$sottoCat</option>";
                   if(
$j==$max){ 
                        echo 
"</optgroup>";
                   }
                 }else{
                  echo 
"<option>$Cat</option>";
                  }
                    
              }
    }
    echo 
"<option value='aggiungi'>Aggiungi una nuova categoria</option>
    </select>"

purtroppo vedo perfettamente il primo gruppo... poi non vedo + nulla
Come mai?