Jump to content

Creating infinte drop down menus


dc_jt

Recommended Posts

Hi I have categories which contain sub categories which contain other sub categories etc etc....

 

Ive got a drop down which shows the first lot of categories, then another drop down displaying the sub categories depending on what the user clicked in the first place. Then another displaying the next set of sub categories depending on what they chose in the second drop down etc.

 

However, there could be hundreds of sub categories within each category therefore I need to create one drop down which can then create other drop downs if there are any sub categories in that category. (Hope your still with me)

 

I cant literally create 100 drop downs therefore what is the best way to do this? Maybe using an increment? Here are the three drop downs so far anyway:

 

<?php 
require_once(LOCAL_CLASSES.'RCLTblCategories.class.php');
$oTblCategories = new RCLTblCategories();
$rCategories = $oTblCategories->GetCategories();
$rCategories2 = $oTblCategories->GetCategories2($_POST['category']);
$rCategories3 = $oTblCategories->GetCategories3($_POST['category2']);

?>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="tabpagemain">
<form name="category" action="<?=$_SERVER['PHP_SELF']?>" method="POST">		
<tr>
      <td>Category</td>

<td> <select name="category">

<option value="0">-- View All --</option>
  <?php

  while ($oCategories = mysql_fetch_object($rCategories))

  {?>

    <option value="<?=$oCategories->category_id?>"<?=($_POST['category'] == $oCategories->category_id)?' selected="selected"':''?>><?=$oCategories->name ?></option>

    <?php } ?>


</select>
<td colspan="2"><input type="Submit" name="submit" value="Submit" class="cmdbutton" /></td>
</tr>
<input type="hidden" name="mode" value="apply" />

</table>
<?php if($_POST['submit'] || $_POST['submit2']){?>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="tabpagemain">	
<tr>
      <td>Sub Category</td>

<td> <select name="category2">

<option value="0">-- View All --</option>
  <?php

  while ($oCategories2 = mysql_fetch_object($rCategories2))

  {?>

    <option value="<?=$oCategories2->category_id?>"<?=($_POST['category2'] == $oCategories2->category_id)?' selected="selected"':''?>><?=$oCategories2->name ?></option>

    <?php } ?>


</select>
<td colspan="2"><input type="Submit" name="submit2" value="Submit" class="cmdbutton" /></td>
</tr>
<input type="hidden" name="mode" value="apply" />

</table>
<?php } ?>

<?php if($_POST['submit2']){?>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0" class="tabpagemain">		
<tr>
      <td>Sub Category 2</td>

<td> <select name="category3">

<option value="0">-- View All --</option>
  <?php

  while ($oCategories3 = mysql_fetch_object($rCategories3))

  {?>

    <option value="<?=$oCategories3->category_id?>"<?=($_POST['category3'] == $oCategories3->category_id)?' selected="selected"':''?>><?=$oCategories3->name ?></option>

    <?php } ?>


</select>
<td colspan="2"><input type="Submit" name="submit3" value="Submit" class="cmdbutton" /></td>
</tr>
<input type="hidden" name="mode" value="apply" />
</form>
</table>
<?php } ?>

 

Hope someone can help?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/41794-creating-infinte-drop-down-menus/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.