父级和子类别下拉菜单

I'm using Smarty, PHP and MySQL.

This should be very easy for someone that understands how to do this. I'm a noob and have no idea.

Trying to get a horizontal nav bar with parent and subcategories in the drop down.

The current code only displays the parent and I need the subcategories to display under.

I don't think I have any SQL to get the subcats and don't really know how to write it, so maybe someone 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 to get Categories

 // list of all categories
function getCategoriesList($include_subcats = false) {

 $where = '';

 if ($include_subcats != false) {
   $where = ' where parent_id = 0 ';
 }
$list =
 getSqlResult(
   "select * from category $where ORDER BY parent_id ASC",
   SQL_RESULT_ALL);

 return $list;
}

Template Code to Display the 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 do it to return the function

firstly we will write parents because their catid is 0

              function categori($upcatid=0, $satir=0, $bosluk=""){
            // $upcatid  is 0 for began that means is we will see the all parent
                $data["result"]= $categori->kategori($upcatid);// i got my all cats from db
                foreach ($data["result"] as $key => $kategorim) {
        // lets look at the cats parent categories parent_id are 0 if categori parent is not 0 it main the categori have parent! so we are going to return the function and call the parent firstly

                if(!isset($disabled))
                     $disabled='';
                echo '<option value="'.$kategorim["id"].'" '.$disabled.' >'.str_repeat("->>", $satir).">$bosluk ".$kategorim["catname"].'</option>';
   categori($kategorim["id"], $satir+1); // now get the categori id and retun the function  
    //call the all childs of the cat.

                }
            }

i wrote all 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 you need to modify your project