Links

"; foreach ($root_categories as $category_id) { print_category($category_id); } print ""; function get_root_categories() { $result = mysql_query("select * from links_category ". "where parent_id IS NULL order by name"); $categories = array(); while ($row = mysql_fetch_array($result)) { $categories[] = $row['id']; } return $categories; } function get_sub_categories($category_id) { $result = mysql_query("select * from links_category ". "where parent_id = $category_id order by name"); $categories = array(); while ($row = mysql_fetch_array($result)) { $categories[] = $row['id']; } return $categories; } function print_category($category_id) { // First print the name of this category. $result = mysql_query("select * from links_category where id = $category_id"); $row = mysql_fetch_array($result); print "
  • " . $row['name'] . " - " . $row['description'] . "
  • "; // Then print all the links in this category. print ""; // And recursively call this function for all sub-categories. $sub_categories = get_sub_categories($category_id); if (count($sub_categories) > 0) { foreach ($sub_categories as $sub_category_id) { print "
    "; } } } // Prints all the links in this category. Each entry is printed on a //
  • item and therefore needs an around it. function print_category_links($category_id) { $result = mysql_query("select * from links where category_id = $category_id order by name"); while ($row = mysql_fetch_array($result)) { print "
  • " . "" . $row['name'] . "". " - ". $row['description']. "
  • "; } } ?>