Welcome to WebmasterWorld Guest from 54.145.166.96

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Dynamic drop down list

   
1:20 pm on Feb 1, 2006 (gmt 0)

10+ Year Member



Hi,

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 &nbsp 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>

5:03 pm on Feb 1, 2006 (gmt 0)

10+ Year Member



$display.="<option value=$DBcatid>&nbsp;&nbsp;$DBcatid\n"; // indented two spaces
5:42 pm on Feb 1, 2006 (gmt 0)

10+ Year Member



Thanks Salsa.

I'll give that a go.

Thanks for the response.

Woldie.

9:35 am on Feb 2, 2006 (gmt 0)

10+ Year Member



Hi everyone,

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="&nbsp;&nbsp;&nbsp;&nbsp;";
}

if ($width==72)
{
$spaces="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

if ($width==96)
{
$spaces="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

if ($DBcatid==1)
{
$display="<option value=$DBcatid>$spaces";
}
else
{
$display="<option value=$DBcatid>$spaces";
}

$display.="$DBcatname</option>";
echo $display;
maketree($DBcatid,$level+1);
}
}

 

Featured Threads

Hot Threads This Week

Hot Threads This Month