Home > Article > Backend Development > Unlimited classification php recursive function_PHP tutorial
This infinite classification php recursive function is a recursive query method between php and sql. It is very simple to query whether there are no subcategories in the current category. If there are, then call the function itself to operate. If there are no subcategories, Once the class is reached, you can return.
This infinite classification php tutorial recursive function is a recursive query method between php and sql. It is very simple to query whether there are no subcategories in the current category. If there are, then call the function itself to operate. If there are no subcategories, then call the function itself to operate. It can be returned if it is subclassed.
function createsortoptions ($selected=0,$parent_id=0,$n=-1)
{
global $db;
$sql = "select * from `@__article_sort` where `parent_id` = '{$parent_id}'";
$options = ";
static $i = 0;
if ($i == 0)
{
$options .= ' if ($row['sort_id'] == $selected)
{
$options .=' selected ';
}
$options .=">".str_repeat(' ',$n*3).$row['sort_name']."n";
$options .=createsortoptions ($selected,$row['sort_id'],$n);
}
}
return $options;
}
If you are using smarty template, you can call it as follows
//– $tpl->assign('sort_list',createsortoptions ());
//– $tpl->assign('sort_list',createsortoptions ($sort_id));