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
Share on other sites

Instead of creating hundreds of dropdowns why don't you create a function that will recursively list the sub-categories of the selected category as well as its parent categories in a single drop down with sub categories slightly indented..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.