Php mysql menu system

Hi, wrote earlier about making php menu class. Now I’ve made my solution to render menus from DB. Although this solution works in my case I’m sure that this can be improved. This is third level menu script. How can use recursive function to automaticly render nested menus.
Here is the code
menu class

    public static function readMenuRoot(){
          return self::find_by_sql("SELECT * FROM menu WHERE parent_id = 0");
   public static function getChildren($id){
        global $database;
        $children = array(); 
        $sql = "SELECT menu_id, parent_id, description, name, location FROM menu WHERE parent_id = '$id' ";
        $result_set = $database->query($sql);
        $count = 0; 
        while ($row = $database->fetch_array($result_set)) {
  			$children[$count]["menu_id"] = $row["menu_id"]; 
            $children[$count]["parent_id"] = $row["parent_id"]; 
            $children[$count]["location"] = $row["location"]; 
            $children[$count]["name"] = $row["name"];
            $children[$count]["description"] = $row["description"];
		return $children;

and this is how I render this

<ul id="nav">
	$mojmeni = Menu::readMenuRoot();	
	foreach ($mojmeni as $mm){
		$id = $mm->menu_id; 
		$name = $mm->name;
		$location = $mm->location; 
		$id = $mm->menu_id;
		$parent = $mm->parent_id;

				$level1 =  Menu::getChildren($id);			
				echo "<li><a href=\\"$location\\">$name</a>";								
				//id submeni id == parent_id than show submenu
				if ($id == $level1[$x]["parent_id"]){ 
					echo "<ul>"; 
					for ($x=0; $x<sizeof($level1); $x++) {
						echo "<li> <a href=\\" ". $level1[$x]["location"] ." \\">" . $level1[$x]["name"] . "</a>";
						$level2 = Menu::getChildren($level1[$x]["menu_id"]);
						if ($level2 != 0){
							//has submenu
							if ($level1[$x]["menu_id"] == $level2[$x]["parent_id"]){ 
								echo "<ul>"; 
								for ($y=0; $y<sizeof($level2); $y++) {
									echo "<li> <a href=\\" ". $level2[$y]["location"] ." \\">" . $level2[$y]["name"] . "</a>";
									$level3 = Menu::getChildren($level2[$y]["menu_id"]);
									if ($level3 != 0){
										if($level2[$y]["menu_id"] == $level3[$z]["parent_id"]){
											echo "<ul>";
											for($z=0; $z<sizeof($level3); $z++){
												echo "<li> <a href=\\" ". $level3[$z]["location"] ." \\">" . $level3[$z]["name"] . "</a></li>";
											}echo "</ul>";//close level3
									} //level 3 
								}echo "</ul>";//close level 2 				
						}else echo "</li>";//level2 
					}echo "</ul>";
				}echo "</li>";//close root meni

	}// end foreach

I’ve found this second file which is rendering menu kind a dirty code. How can I improve this with function renderDropDownMenu();
and for other example renderTreeMenu();


Check this out: