php - Parent and SubCategory Drop Down Menu -


i'm using smarty, php , mysql.

this should easy understands how this. i'm noob , have no idea.

trying horizontal nav bar parent , subcategories in drop down.

the current code displays parent , need subcategories display under.

i don't think have sql subcats , don't know how write it, maybe can help.

table >>> category      category_id  name      parent_id     1            parent    0     2            parent    0     2            parent    0     3            child     1     4            child     2     5            child     2     6            child     3     7            child     3 

current function categories

 // list of categories function getcategorieslist($include_subcats = false) {   $where = '';   if ($include_subcats != false) {    $where = ' parent_id = 0 ';  } $list =  getsqlresult(    "select * category $where order parent_id asc",    sql_result_all);   return $list; } 

template code display menu

{foreach name=categorieslist from=$categorieslist item=i} <li class="dropdown "><a href="/{$i.category_filename}" class="dropdown-toggle" data-toggle="dropdown">{$i.category_name}<b class="caret"></b></a </li>{/foreach} 

you can return function

firstly write parents because catid 0

              function categori($upcatid=0, $satir=0, $bosluk=""){             // $upcatid  0 began means see parent                 $data["result"]= $categori->kategori($upcatid);// got cats db                 foreach ($data["result"] $key => $kategorim) {         // lets @ cats parent categories parent_id 0 if categori parent not 0 main categori have parent! going return function , call parent firstly                  if(!isset($disabled))                      $disabled='';                 echo '<option value="'.$kategorim["id"].'" '.$disabled.' >'.str_repeat("->>", $satir).">$bosluk ".$kategorim["catname"].'</option>';    categori($kategorim["id"], $satir+1); // categori id , retun function       //call childs of cat.                  }             } 

i wrote categories in select options

if($upcatid==0) echo ' <li class="dropdown">               <a data-toggle="dropdown" class="dropdown-toggle" href="#">'.$kategorim["catname"].' <b class="caret"></b></a>  '; elseif($upcatid!==0){ echo '  <li class="dropdown-submenu">                   <a href="#">'.$kategorim["catname"].'</a>                   <ul class="dropdown-menu">                     <li><a href="#">'.categori($kategorim["id"], $satir+1).'</a></li>                    </ul>                 </li>';   echo '</li>'; 

all need modify project