php - Generating Dynamic Navbar based on SQL results? -


hello superiors coders.

im trying make shop section part of website includes sidebar navbar can clicked specify sections of product e.g. electrical or cctv. i've done allocating products category , generate navbar querying categories , looping through creating html bar displays categories

example

<div class="leftside" id="leftbar"> <nav class="menu-top">     <ul class="off-canvas-list" style="font-size: 25px;font-weight: bold">         <li style="padding-top: 2.7rem"></li>         <?php foreach ($item_list $list) {             echo "<li><a href='/welcome/shop_search/" . $list->type . "'>" . $list->type . "</a></li>";         }         ?>     </ul> </nav> 

the problem want able use sub categories have not got clue how sql data should set out how incorporate intelligence loop through add main categories , add dropdown sub categories.

+------------+----------------+------+-----+---------+ | id         | name           | main | sub | parent  | +------------+----------------+------+-----+---------+ | 1          | cabling        |  1   | 0   |         |  | 2          | network cable  |  0   | 1   | cabling |  | 2          | electric cable |  0   | 1   | cabling |  +------------+----------------+------+-----+---------+ 

this how i've set sql , i'm aiming put sort of logical if statement how binding sub categories main category when loop has finished creates navbar mains being buttons , sub categories in collapsable inside relevant main.

you have make select in each iteration:

<div class="leftside" id="leftbar"> <nav class="menu-top"> <ul class="off-canvas-list" style="font-size: 25px;font-weight: bold">     <li style="padding-top: 2.7rem"></li>     <?php foreach ($item_list $list) {         echo "<li><a href='/welcome/shop_search/" . $list->type . "'>" . $list->type . "</a></li>";           //select * types sub=list->type         //$num_rows = mysql_num_rows($select)         if($num_rows>0){             echo '<ul>';                 //for each                 //sub             echo '</ul>';         }     }     ?> </ul> 

for design recomend bootstrap navbar


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -