table('arti"/> table('arti">

Home >Backend Development >PHP Tutorial >Return to base PHP code to use array to return infinite classified list data

Return to base PHP code to use array to return infinite classified list data

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:43:32880browse

Copy the code The code is as follows:


/*—————————————————————— */
//– Get list data of unlimited categories
/*—— —————————————————— */
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;
}

The above introduces the code for returning to base PHP using an array to return infinite categories of list data, including the content of returning to base. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn