homepage Welcome to WebmasterWorld Guest from 54.226.180.223
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Dynamic drop down list
woldie




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

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>

 

Salsa




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

$display.="<option value=$DBcatid>&nbsp;&nbsp;$DBcatid\n"; // indented two spaces
woldie




msg:1253291
 5:42 pm on Feb 1, 2006 (gmt 0)

Thanks Salsa.

I'll give that a go.

Thanks for the response.

Woldie.

woldie




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

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);
}
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved