PHP USES an array to return code for an infinite list of sorted data

  • 2020-03-31 21:07:53
  • OfStack

 
 
//Returns the list data for an infinite class
 
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; 
} 

Related articles: