$selcats="SELECT * from mcs_content_cat ORDER BY CatName ASC";
$selcats2=mysql_query($selcats) or die("Could not get categories");
while($selcats3=mysql_fetch_array($getcats2))
{
}
$selcat="SELECT * from mcs_content_cat ORDER BY CatName ASC";
$selcat2=mysql_query($selcat) or die("Could not select CatID");
traverse(0,0,$selcat2);
echo $selcat2;
Traverse Function:
function traverse($root, $depth, $sql)
{
$row=0;
$rows = mysql_num_rows($sql);
while ($row < $rows)
{
mysql_data_seek($sql,$row);
$acat = mysql_fetch_array($sql);
if ($acat['CatParent'] == $root)
{
print "<option value='" . $acat['CatID'] . "'>";
$j=0;
while ($j<$depth)
{
print " ";
$j++;
}
if($depth>0)
{
print "-";
}
print $acat['CatName'] . "</option>";
traverse($acat['CatID'], $depth+1,$sql);
}
$row++;
}
}
|