recursive function category database

后端 未结 4 1924
春和景丽
春和景丽 2021-01-06 16:57

i hoping to create a recursive function which i don\'t have an idea yet

this is my code to fetch category from database

  

        
4条回答
  •  爱一瞬间的悲伤
    2021-01-06 17:38

    What you need to do, is build a recursive function. That is, a function that calls itself within. An example:

    function getCategories($parent=0) {
        $res = mysql_query("SELECT * FROM categories WHERE category_parent = '$id' ORDER BY left ASC");
        if (mysql_num_rows($res) > 0) {
            $category = mysql_fetch_object();
            echo '

    If I've made any typos in regards to table and column names then obviously swap them out for the correct values.

提交回复
热议问题