首页 技术 正文
技术 2022年11月8日
0 收藏 555 点赞 2,112 浏览 1634 个字
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取当前分类下所有子类ID
* @pid:父类ID
*/
function get_child_ids($pid){
return $this->__get_ids($pid,'','id');
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取当前分类下所有父类ID
* @id:子类ID
*/
function get_parent_ids($id){
return $this->__get_ids($id,'','pid');
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-22 11:25:02
* @Description: 获取类下所有父/子类ID
* @pid:多个父/子类ID集以,分隔
* @childids:找到的子/父分类列表
* @find_column:where查找的字段[id|pid:default]
*/
function __get_ids($pid,$childids,$find_column = 'id'){
if(!$pid || $pid<=0 || strlen(pid)<=0 || !in_array($find_column,array('id','pid'))) return 0;
if(!$childids || strlen($childids)<=0) $childids = $pid;
$column = ($find_column =='id'? "pid":"id");//id跟pid为互斥
$ids = $this->model->where("$column in($pid)")->getField("$find_column",true);
$ids = implode(",",$ids); //未找到,返回已经找到的
if($ids<=0) return $childids;
//添加到集合中
$childids .= ','.$ids;
//递归查找
return $this->__get_ids($ids,$childids,$find_column);
}
/**
* @Author: HTL
* @Email: Huangyuan413026@163.com
* @DateTime: 2016-04-07 09:33:27
* @Description: 默认状态更改
*/
function is_default(){
$id = intval($_GET['id']);
$type = intval($_GET['status']);
if ($id>0) {
//取消默认时将取消所有子分类的默认
if($type!=1){
$id = $this->_get_child_ids($id);
}
else{
$id = $this->_get_parent_ids($id);
}
print_r($id);exit;
$rst = $this->model->where("id in($id)")->setField('is_default',$type);
if ($rst) {
$this->success(L("SAVE_SUCCESS"), U("index"));
} else {
$this->error(L('SAVE_ERROR'));
}
} else {
$this->error(L('Parameter_ERROR'));
}
}
CREATE TABLE `thk_material` (
`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`pid` INT(11) NULL DEFAULT '0' COMMENT '父类ID'
);

Thinkphp 获取所有子分类或父分类ID Thinkphp 获取所有子分类或父分类IDThinkphp 获取所有子分类或父分类ID来自为知笔记(Wiz)

上一篇: Active Learning
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902