<?PHP
function GetCats($id='0',$sublev='0',$vname='C_Parent')
{
$DQ = new MySQLTable;
$DQ -> TblName = 'cat_categories';
$WHERE[$vname]['=']=$id;
$res = $DQ -> Select('C_ID,C_Name',$WHERE,'C_ID');
if (mysql_num_rows($res)>0)
{
while($row = mysql_fetch_assoc($res))
{
$ss='';
if($sublev!=='0')
{
for($i=0;$i<=$sublev*10;$i++)
{
$ss.=' ';
}
$ss.='|';
for($i=0;$i<=$sublev;$i++)
{
$ss.='-';
}
$ss.='>>';
}
$sel_s = '';
if(IsSet($_POST['C_Parent']))
{
if($row['C_ID']==$_POST['C_Parent'])
{
$sel_s = ' selected';
}
} elseif (IsSet($_POST['I_Parent'])) {
if($row['C_ID']==$_POST['I_Parent'])
{
$sel_s = ' selected';
}
} else {
$sel_s = '';
}
Echo "<option value=\"".$row['C_ID']."\" ".$sel_s.">".$ss.$row['C_Name']."</option>\r\n";
GetCats($row['C_ID'],$sublev+1);
}
}
}
Echo "<select name=\"C_Parent\">\r\n";
Echo "<option value=\"0\">...</option>\r\n";
GetCats();
Echo "</select>";
?>
Something like this.
But here was my own MySQL class. The query is: SELECT C_ID,C_Name WHERE C_Parent=$id ORDER BY C_ID
where $id - php variable (current parent cat).
And there are $_POST variables if error submit to store selected.
This is not the most effective way to di it bcoz many queries. More effectively is to get all data to array to work with.