三级分类 调用方法

<?php
class Goods {
var $db;

public function __construct($db){
$this->db = $db;
}

/**
* 获得指定分类同级的所有分类以及该分类下的子分类
*
* @access public
* @param integer $cat_id 分类编号
* @return array
*/
function get_categories_tree()
{

/*
判断当前分类中全是是否是底级分类,
如果是取出底级分类上级分类,
如果不是取当前分类及其下的子分类
*/

/* 获取当前分类及其子分类 */
$sql = 'SELECT tID,tname ,two_id,is_show ' .
" from ntc_type where two_id = 0 ORDER BY torder ASC LIMIT 13";
$res = $this->db->select($sql);

foreach ($res AS $k=>$row)
{
if ($row->is_show)
{
$cat_arr[$k]['id'] = $row->tID;
$cat_arr[$k]['name'] = $row->tname;
$cat_arr[$k]['url'] = "index.php?module=shop&action=Category&id=$row->tID";
// $cat_arr[$k]['zdy'] = "123";
$getSon = $this->get_child_tree($row->tID,1);
if ($getSon)
{
$cat_arr[$k]['son'] = $this->get_child_tree($row->tID);
}
}
}
if(isset($cat_arr))
{
return $cat_arr;
}
}

function get_child_tree($tree_id,$get=0)
{
$three_arr = array();

$sql = "SELECT tID, tname, two_id, is_show from ntc_type where two_id = '$tree_id' ORDER BY torder ASC";
$res = $this->db->select($sql);
if($get && empty($res)){
return false;
}
foreach ($res AS $k=>$row)
{
if ($row->is_show)

$three_arr[$k]['id'] = $row->tID;
$three_arr[$k]['name'] = $row->tname;
$three_arr[$k]['url'] = "index.php?module=shop&action=Category&id=$row->tID";

$getSon = $this->get_child_tree($row->tID,1);
if ($getSon)
{
$three_arr[$k]['sunzi'] = $this->get_child_tree($row->tID);

}
}
return $three_arr;
}

 


//自定义页面调用
require_once(MO_LIB_DIR . '/Goods.class.php');

/*商品分类*/
$show = new Goods($db);
$category = $show->get_categories_tree();

 

 


?>

转载于:https://www.cnblogs.com/nonoleng/p/4813575.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值