php遞歸實(shí)現(xiàn)無限分類生成下拉列表的函數(shù)
更新時(shí)間:2010年08月08日 17:44:57 作者:
php自定義函數(shù)之遞歸實(shí)現(xiàn)無限分類生成下拉列表,這樣可以提高效率,不用每次都從數(shù)據(jù)庫讀取數(shù)據(jù)。
復(fù)制代碼 代碼如下:
/*—————————————————— */
//– 遞歸實(shí)現(xiàn)無限分類生成下拉列表函數(shù)
//– $tpl->assign('sort_list',createSortOptions ());
//– $tpl->assign('sort_list',createSortOptions ($sort_id));
/*—————————————————— */
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 .= '<option value="0″ >請(qǐng)選擇</option>';
}
$res = $db->query ($sql);
if ($res)
{
$n++;
while ($row = $db->fetch_assoc ($res))
{
$i++;
$options .="<option value='{$row['sort_id']}'";
if ($row['sort_id'] == $selected)
{
$options .=' selected ';
}
$options .=">".str_repeat(' ',$n*3).$row['sort_name']."</option>\n";
$options .=createSortOptions ($selected,$row['sort_id'],$n);
}
}
return $options;
}
您可能感興趣的文章:
- php實(shí)現(xiàn)無限級(jí)分類(遞歸方法)
- php實(shí)現(xiàn)無限級(jí)分類查詢(遞歸、非遞歸)
- thinkphp實(shí)現(xiàn)無限分類(使用遞歸)
- php無限極分類遞歸排序?qū)崿F(xiàn)方法
- PHP 無限分類三種方式 非函數(shù)的遞歸調(diào)用!
- php遞歸方法實(shí)現(xiàn)無限分類實(shí)例代碼
- PHP實(shí)現(xiàn)遞歸無限級(jí)分類
- php實(shí)現(xiàn)無限級(jí)分類實(shí)現(xiàn)代碼(遞歸方法)
- php 無極分類(遞歸)實(shí)現(xiàn)代碼
- php菜單/評(píng)論數(shù)據(jù)遞歸分級(jí)算法的實(shí)現(xiàn)方法
相關(guān)文章
PHP用SAX解析XML的實(shí)現(xiàn)代碼與問題分析
近日在做一個(gè)解析XML的小程序,因?yàn)榉?wù)器是PHP4的,XML解析函數(shù)只能用SAX方式的xml_parser來解析了。2011-08-08