php - Building unordered list navigation menu with an easier way - Code Beautifying Question -


i wrote dynamic menu based on 3 table on db reflects below level frame:

> section >> categories >>> subcategory 

here code:

include("conndb.php");  echo '<ul>'; $q1 = mysql_query("select * section order section_name asc");  while($getsection = mysql_fetch_array($q1)) {     echo "<li><a href='content.php?sec={$getsection['section_id']}&cat='>{$getsection['section_name']}</a>";      $q2 = mysql_query("select * category section_id = '{$getsection['section_id']}'");     if(mysql_num_rows($q2) > 0) {         echo "<ul>";         while($getcat = mysql_fetch_array($q2)) {             echo "<li><a href='content.php?sec={$getsection['section_id']}&cat={$getcat['category_id']}&scat='>{$getcat['category_name']}</a>";              $q3 = mysql_query("select * subcategory category_id = '{$getcat['category_id']}'");             if(mysql_num_rows($q3) > 0) {                 echo "<ul>";                 while($getsubcat = mysql_fetch_array($q3)) {                     echo "<li><a href='content.php?sec={$getsection['section_id']}&cat={$getcat['category_id']}&scat={$getsubcat['subcategory_id']}&getdetail='>{$getsubcat['subcategory_name']}</a></li>";                 }                 echo "</ul>";                 echo "</li>";             }         }         echo "</ul>";         echo "</li>";     } } echo '</ul>'; 

i wondering if can find beautify basic-level code better way, more professional way? help.

have at:

http://en.wikipedia.org/wiki/nested_set_model

remodel 3 tables one, change recurisve calling 1 sql statement, , little php-looping create list. :)


Comments