I'm trying to dynamically populate a drop down menu with categories and subcategories from a database table. My problem is that I can't figure out a way to loop through the subcategories so they display under the correct category.
In my SQL database I have a table called 'Categories' with 3 columns: id, category, subcategory. The subcategories in the subcategory column are separated by 3 colon marks (Artists:::Childcare:::Classes:::Event).
I'm using unordered lists <Ul> <li> in html to populate the drop down menu.
This code displays the category names:
Code:$reqr1="select * from $categoryTable"; $resultre1=mysql_query($reqr1); <?php while($allCategories=mysql_fetch_assoc($resultre1)){ ?> <li><a href="#"><div class="whatever"<?php print $relanguage_tags[$allCategories['category']];?>' <?php if(in_array($relanguage_tags[$allCategories['category']],$reCategory)) print "selected='selected'"; ?> ><?php print $relanguage_tags[$allCategories['category']]; ?></div></a> <?php } ?>
This code loops through the subcategories but it is a work in progress
Code:<?php if($ptype=="showOnMap" || $ptype=="viewFullListing" || $ptype=="home" || $ptype==""){ $reCategoryString=getCommaStringFromArray($reCategory); $reqr2="select * from $categoryTable where id like '%' ".getRealValue($reCategoryString,"reCategory"); $resultre2=mysql_query($reqr2); ?> <?php while($allSubCategories=mysql_fetch_assoc($resultre2)){ $subCatList=explode(":::",$allSubCategories['subcategories']); $subCatSize=sizeof($subCatList); for($i=0;$i<$subCatSize;$i++){ ?> <li><a href="#"><div class="whatever"<?php print $relanguage_tags[$subCatList[$i]];?>' <?php if(in_array($relanguage_tags[$subCatList[$i]],$reSubcategory)) print "selected='selected'"; ?> ><?php print $relanguage_tags[$subCatList[$i]]; ?></div></a></li> <?php } } ?> <?php } ?>


Reply With Quote
Bookmarks