dc_jt Posted March 8, 2007 Share Posted March 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
magnetica Posted March 8, 2007 Share Posted March 8, 2007 Your on the right tracks but try and echo a drop down list within the while loop. Quote Link to comment Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 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.. Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks for your replies but I need to have separate drop downs I think! Any other ideas? Quote Link to comment Share on other sites More sharing options...
dhimok Posted March 8, 2007 Share Posted March 8, 2007 Read this thread and you will find the solution http://www.phpfreaks.com/forums/index.php/topic,116245.0.html Quote Link to comment Share on other sites More sharing options...
dc_jt Posted March 8, 2007 Author Share Posted March 8, 2007 It needs to be drop downs. I already have a tree, however there is thousands of data which the server cannot handle using this way, therefore Im trying to cut it down using drop down menus. ??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.