first of all, new mysqli , prepare statements please let me know if see error. have static drop down menu : 
html code:
<ul class="menu sgray fade" id="menu"> <li><a href="#">bike</a> <!-- start mega menu --> <div class="cols3"> <div class="col1"> <ol> <li><a href="#">bikes</a></li> <li><a href="#">wheels</a></li> <li><a href="#">helmets</a></li> <li><a href="#">components</a></li> </ol> </div> <div class="col1"> <ol> <li><a href="#">pedals</a></li> <li><a href="#">gps</a></li> <li><a href="#">pumps</a></li> <li><a href="#">bike storage</a></li> </ol> </div> <div class="col1"> <ol> <li><a href="#">power meters</a></li> <li><a href="#">hydratation system</a></li> <li><a href="#">shoes</a></li> <li><a href="#">saddles</a></li> </ol> </div> </div> <!-- end mega menu --> </li> i want make dynamic dropdown menu. managed show $categoryname , $subcategoryname function:
function showmenucategory(){ $db = db_connect(); $query = "select * category"; $stmt = $db->prepare($query); $stmt->execute(); $stmt->bind_result($id,$categoryname,$description,$pic,$active); while($stmt->fetch()) { echo'<li><a href="#">'.$categoryname.'</a> <!-- start mega menu --> <div class="cols3"> <div class="col1"> <ol>'; $dba = db_connect(); $subquery = "select * subcategory categoryid = '".$id."'"; $substmt = $dba->prepare($subquery); $substmt->execute(); $substmt->bind_result($subid,$catid,$subcategoryname,$subdescription); while($substmt->fetch()) { echo' <li><a href="#">'.$subcategoryname.'</a></li>'; } echo' </ol> </div> <!-- end mega menu --> </li>'; } } the problem returns subcategories on the same <div class="col1">:

what obtain count subcategories , if result more 4 return other items in second , third column.
update***: answer below menu looks this:

thanks!
how try this?
to explain further
what happening every subcategory fetched, increment counter. if counter hits 4, ends <ul> , <div> , creates new 1 represent new column.
function showmenucategory(){ $db = db_connect(); $query = "select * category"; $stmt = $db->prepare($query); $stmt->execute(); $stmt->bind_result($id,$categoryname,$description,$pic,$active); while($stmt->fetch()) { echo'<li><a href="#">'.$categoryname.'</a> <!-- start mega menu --> <div class="cols3"> <div class="col1"> <ol>'; $dba = db_connect(); $subquery = "select * subcategory categoryid = '".$id."'"; $substmt = $dba->prepare($subquery); $substmt->execute(); $substmt->bind_result($subid,$catid,$subcategoryname,$subdescription); $count = 0; while($substmt->fetch()) { echo' <li><a href="#">'.$subcategoryname.'</a></li>'; $count+=1; if ($count == 4) { $count = 0; echo '</ol></div><div class="col1"><ol>'; } } echo' </ol> </div> <!-- end mega menu --> </li>'; } } edit: misunderstood purpose of col1. should col1 , should work now. if not, leave me comment!
Comments
Post a Comment