新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
無線分類新寫法,是不是很吊@!
* @license
* @Copyright (c) 2009-2016 http://www.lvmaque.com All rights reserved.
*/
class Model_Shop_Class{
protected $_table_name = 'shop_goods_class';
protected $_primary_key= 'gc_id';
/**
* ***************************************************************
* 獲得排列好的分類信息 2016年04月26日18:43:22
* ***************************************************************
* @param
* @return void
* @author 王迪<2880707519@qq.com>
* @license
* @Copyright (c) 2009-2016 http://www.lvmaque.com All rights reserved.
*/
public static function getList(){
$parent_0 = "select gc_id,gc_parent_id from sline_shop_goods_class where gc_parent_id=0";
$list = DB::query(Kohana_Database::SELECT,$parent_0)->execute()->as_array();
$parentArray=array();
$parentArray[0]=$list;
$parentArray['findIds']=$list;
self::getChild($parentArray);
return $parentArray;
}
//查找子集
public static function getChild(&$parent){
//id的數(shù)組
$idArray = Kohana_Util::only_array($parent['findIds'],'gc_id');
//id連接城字符串
$idString = implode(',',$idArray);
$child = "select gc_id,gc_parent_id from sline_shop_goods_class where gc_parent_id in ({$idString})";
$childRes = DB::query(Kohana_Database::SELECT,$child)->execute()->as_array();
if(count($childRes)<1){
return;
}
$parent['findIds']=$childRes;
//按parent_id把數(shù)組存儲起來
foreach($childRes as $v){
$parent[$v['gc_parent_id']][]=$v;
}
self::getChild($parent);
}
}這么做查數(shù)據庫的效率會比較高,是一層一層的往下查的

福海網站建設公司創(chuàng)新互聯(lián),福海網站設計制作,有大型網站制作公司豐富經驗。已為福海上千家提供企業(yè)網站建設服務。企業(yè)網站搭建\外貿網站制作要多少錢,請找那個售后服務好的福海做網站的公司定做!
找子集的時候就從parent_id等于零開始查找,
然后循環(huán)0鍵值對應的數(shù)組,
再找里面的parent_id對應的鍵值是否存在,如果存在就把里面的繼續(xù)遍歷,如果不存在就結束遞歸!
O(∩_∩)O哈哈哈~!,我是不是很6,絕對原創(chuàng),親!轉載只要998!
分享文章:無線分類新寫法,是不是很吊@!
URL標題:http://www.dlmjj.cn/article/iispei.html


咨詢
建站咨詢
