ciao

sto cercando di fare un elenco di categorie con le relative sottocategorie solo che mi escono tutte le sottocategorie sotto ciascuna categoria, anzichè uscire solo quelle a cui appartengono:

Codice PHP:
<?
    $query
="SELECT d_protocollo_categ.*
            FROM d_protocollo_categ ORDER BY numero_categ"
;
    
$ris_query=mysql_query($query$conn);
    while(
$row10=mysql_fetch_array($ris_query)){?>

     <tr>
    <td height="41"><span class="testo_rosso_bold"><a href="<?=$PHP_SELF?>?protocollo_categ=<?=$row10[id_protocolli_categ]?>&pagina=2" class="tre">[img]../images/menu_triangolo.gif[/img]
      <?=$row10['numero_categ']?></a></span></td>
    <td align="left"><span class="testo_rosso_bold"><?=$row10['nome_categ']?>
    </span></td>
    </tr>
      <tr>
    <td height="1" colspan="2" valign="top" bgcolor="BE743F"></td>
    </tr>
<?
    $query20
="SELECT d_protocollo_sottocateg.*
              FROM d_protocollo_sottocateg ORDER BY numero_sottocateg"
;
    
$result20=mysql_query($query20$conn);
    
$row20 mysql_fetch_array($result20);
    if (
$row20!=0){
    
$result20 mysql_query($query20$conn);
    while (
$row20 mysql_fetch_array($result20)){?>

     <tr>
    <td height="20"><span class="testo_grigio_bold"><a href="<?=$PHP_SELF?>?protocollo_sottocateg=<?=$row20[id_protocolli_sottocateg]?>&pagina=2">[img]../images/menu_triangolo_arancio.gif[/img]
      <?=$row20['numero_sottocateg']?></a></span></td>
    <td align="left"><span class="testo_grigio_bold"><?=$row20['nome_sottocateg']?>
    </span></td>
    </tr>
      <tr>
    <td height="1" colspan="2" valign="top" bgcolor="BE743F"></td>
    </tr>

<?
}
}
}
?>
ho provato a mettere nella seconda query
Codice PHP:
WHERE sottocategorie=$id_protocolli_categ 
ma non mi funziona. Dove sbaglio?