php用數(shù)組返回無限分類的列表數(shù)據(jù)的代碼
更新時間:2010年08月08日 17:42:14 作者:
php自定義函數(shù)之用數(shù)組返回無限分類的列表數(shù)據(jù),這樣的實現(xiàn)可以提高執(zhí)行的效率不要每次都從數(shù)據(jù)庫讀取數(shù)據(jù)。
復制代碼 代碼如下:
/*—————————————————— */
//– 獲取無限分類的列表數(shù)據(jù)
/*—————————————————— */
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;
}
相關(guān)文章
淺析使用Turck-mmcache編譯來加速、優(yōu)化PHP代碼
本篇文章是對使用Turck-mmcache編譯來加速、優(yōu)化PHP代碼進行了詳細的分析介紹,需要的朋友參考下
2013-06-06
php版微信支付api.mch.weixin.qq.com域名解析慢原因與解決方法
這篇文章主要介紹了php版微信支付api.mch.weixin.qq.com域名解析慢原因與解決方法,詳細分析了微信支付api.mch.weixin.qq.com域名解析慢原因與使用curl_easy_setopt指定ipv4解決ipv6解析問題的相關(guān)技巧,需要的朋友可以參考下
2016-10-10 
