Forum Moderators: coopster

Message Too Old, No Replies

PHP and javascript to select directory or category

Browse path using drop down boxes

         

thing3b

11:00 am on Sep 29, 2005 (gmt 0)

10+ Year Member



I have a large directory of items similar to that of DMOZ.
(no I am not creating another DMOZ look-a-like)

I have a form that I use to edit a item in the directory. One property / variable on this form is the directory that this item is currently contained in.

There are too many directories to just list them in one drop down box, so what I would like to do is create a system (Dynamic Dropdown Boxes) where the user can select the first level directory from a dropdown box. If there are subdirectories, I want a second dropdown box to be availible for the use to select.

I have many levels of directories and in some cases can get up to 8 levels deep.

The seems to be lots of javascript examples to show 2 levels, but I am having a problem adapting the examples to be dynamic-ly created by PHP when the page is requested.

All my data is from a tree of PHP5 objects, but I would be able to adapt an example that took in a multilevel php array.

Can anyone help, or point me to some examples?

[edited by: coopster at 1:27 pm (utc) on Sep. 29, 2005]
[edit reason] removed url per TOS [webmasterworld.com] [/edit]

omoutop

11:43 am on Sep 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi!

this is a simple example of a two level script...

////////////////////////////////////
select name="location" onChange="MM_jumpMenu('parent',this,0)">
<option value="<? echo $location?>"><? echo $location?></option>
<?
$Querylocation = "select distinct location from Location ";
$result = mysql_query($Querylocation);
while ($row=mysql_fetch_assoc($result))
{
$location = $row ['location'];
?>
<option value="hotels.php?location=<? echo $location?>"><? echo $location?></option>
<?
};
?>
</select>
</div></td>
</tr>
<tr>
<td height="24" bgcolor="505c68"> <p align="left"><font color="#FFFFFF"><strong>Town:</strong></font></p></td>
<td bgcolor="#505c68"> <div align="center"><strong><font color="#FFFFFF">Please
Select...</font></strong>
<select name="town">
<? $QueryID = "select ID from Location where location = '$Location'";
$resultID = mysql_query($QueryID);
while ($row3 = mysql_fetch_assoc($resultID))
{
$ID = $row3 ['ID'];
}
$Querytown = "select * from Town join Location on Town.LocationID = Location.ID where LocationID = '$ID'";
$result2 = mysql_query($Querytown);
while ($row2=mysql_fetch_assoc($result2))
{

$town = $row2 ['town'];

?>
<option value="<? echo $town?>"><? echo $town?></option>
<?
};
?>
</select>