Forum Moderators: coopster
What I am trying to achieve is when you have a form drop down menu, it displays all the categories from the directory, with all the indentations. Something like when you submit your site to a directory.
Now I've got it almost working, but I can figure out how to indent it. The code below, I've used a spacer gif, but obviously that won't work!
I will need to use   command but not quite sure how to code it?
Any help appreciated - thanks.
function maketree($rootcatid,$level)
{
$sql="select catid,cat_name
from tbl_name
where parentid=$rootcatid
order by cat_name";
$result=mysql_query($sql);
while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
{
$width=($level+1)*24;
$display="<img src=/_images/spacer.gif border=0 width=$width height=12>";
if ($DBcatid==1)
{
$display.="<option value=$DBcatid>";
}
else
{
$display.="<option value=$DBcatid>";
}
$display.="$DBcatname";
echo $display;
maketree($DBcatid,$level+1);
}
}
?>
<table cellpadding="2" cellspacing="2" border="0" width="width="100%"">
<tr>
<td><select name="">
<? maketree(0,0);?>
</select></td>
</tr>
</table>
Got it to work, thanks goes to Salsa :o)
Woldie.
function maketree($rootcatid,$level)
{
$sql="select catid,cat_name
from tbl_name
where parentid=$rootcatid
order by cat_name";
$result=mysql_query($sql);
while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
{
$width=($level+1)*24;
if ($width==48)
{
$spaces=" ";
}
if ($width==72)
{
$spaces=" ";
}
if ($width==96)
{
$spaces=" ";
}
if ($DBcatid==1)
{
$display="<option value=$DBcatid>$spaces";
}
else
{
$display="<option value=$DBcatid>$spaces";
}
$display.="$DBcatname</option>";
echo $display;
maketree($DBcatid,$level+1);
}
}