Php user-defined functions use arrays to return list data of infinite categories. this can improve execution efficiency rather than reading data from the database every time.
The code is as follows:
/*------------------*/
//-Obtain the list data of an unlimited category
/*------------------*/
Function get_sort ($ parent_id = 0, $ n =-1)
{
Global $ db;
Static $ sort_list = array ();
$ SQL = "SELECT * FROM". $ db-> table ('article _ sort '). "WHERE 'parent _ id' =' {$ parent_id }'";
$ Res = $ db-> query ($ SQL );
If ($ res)
{
$ N ++;
While ($ row = $ db-> fetch_assoc ($ res ))
{
$ SQL = "SELECT * FROM ". $ db-> table ('article _ sort '). "WHERE 'parent _ id' = '{$ row ['sort _ id']}'";
$ Children = $ db-> num_rows ($ SQL );
$ Row ['sort _ name'] = str_repeat ('', $ n * 4). $ row ['sort _ name'];
$ Row ['Children '] = $ children;
$ Sort_list [] = $ row;
Get_sort ($ row ['sort _ id'], $ n );
}
}
Return $ sort_list;
}