三级分类 调用方法
2015-09-16 15:56
288 查看
<?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();
?>
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();
?>
相关文章推荐
- fragment 数据传递,通信
- 接口和抽象类的区别,这种题目有意思吗?
- 创建ActiveX简单步骤
- android模拟器的判定
- jar 打包详解
- Qt 学习之路:QStringListModel
- ListView的Item被点击和其中的Button被点击同时生效
- sass
- qml学习------------Grid(网格布局)
- Android开发学习笔记:浅谈显示Intent和隐式Intent
- MysqlL-5.6免安装版配置方法
- ANR类型及解决方法 && 基本算法 && HashMap原理
- 一般线性规划求最大值
- UVA - 11165 Galactic Travel(bfs+尺取法+并查集)
- replace限制文本框只能输入数字,数字和字母等的正则表达式
- cocos2dx3.1-lua移植android流程
- Python网络爬虫 - 3. 异常处理
- 大数据笔记02:大数据之Hadoop的生态系统和版本
- 使用关节型
- rt serial 的编写