当前位置:网站首页>三级分类展示
三级分类展示
2022-06-11 13:20:00 【付先生F】
展示效果:如图
上代码 用的是Yii框架
/** isdelete 删除的状态 1:为展示 pid = 0 为一级 status = 1 是为浙状态开启 */
$sql = 'select * from {
{分类的表名}} where eid = 1231 and isdelete = 1 and pid = 0 and status = 1 ';
$res = Yii::app()->db->createCommand($sql)->queryAll();
foreach ($res as $k => $v) {
// 定义一个空数组为二级分类的名字
$res[$k]['child'] = [];
// 查询二级分类。条件为父id等于等级分类的id
$sql1 = 'select * from {
{分类的表名}} where eid = 1231 and isdelete = 1 and pid = '.$v['id'].' and status = 1 ';
$res1 = Yii::app()->db->createCommand($sql1)->queryAll();
foreach ($res1 as $k1 => $v1) {
// 把查询出来的结果合并到定义的数组中,合并一级二级分类
array_push($res[$k]['child'], $v1);
// 再定义一个数组为三级分类的名字
$res[$k]['child'][$k1]['chlid2'] = [];
// 获取三级分类的信息
$sql2 = 'select * from {
{分类的表名}} where eid = 1231 and isdelete = 1 and pid = '.$v1['id'].' and status = 1 ';
$res2 = Yii::app()->db->createCommand($sql2)->queryAll();
foreach ($res2 as $v2) {
// 合并一级二级三级分类
array_push($res[$k]['child'][$k1]['chlid2'], $v2);
}
}
}
边栏推荐
- From quic to TCP
- SQL:如何用采购单销售单的数据 通过移动加权平均法 计算商品成本
- LNMP deployment
- Unity detects whether the object is within the viewing cone of the camera
- NFT市场怎么样 为什么NFT能如此火爆 怎么搭建NFT平台
- 漫谈软件缺陷与漏洞
- Go 如何减少供应链攻击?
- 字节真的是宇宙尽头吗?
- 【信号去噪】基于稀疏性 (BEADS) 实现色谱基线估计和去噪附matlab代码和论文
- How about NFT market? Why is NFT so popular? How to build NFT platform
猜你喜欢

JDBC connection pool is used for batch import. 5million data are run each time, but various problems will occur in the middle

Introduction to common fonts

苹果将造搜索引擎?

启封easy QF PDA帮助企业提升ERP的管理水平

常用字体介绍

微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!

字节真的是宇宙尽头吗?

Can't understand kotlin source code? Starting with the contracts function~

Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
](/img/43/c828e1cd8273c4d32397ff3e2d23cc.png)
工作总结之因为笛卡尔积问题写SQL搞了半天[害](附笛卡尔积总结)
随机推荐
Application choreography nomad vs. kubernetes
如何写出高性能代码(四)优化数据访问
关于分布式锁的续命问题——基于Redis实现的分布式锁
How to synchronize openstack RDO source to local for offline installation
@How to resolve controller and requestmapping
常用字体介绍
On the life extension of distributed locks -- redis based distributed locks
SAP Spartacus 中的 checkout(结帐) 设计
Chapter V data type (IV)
Explain in detail the differences between real participation formal parameters in C language
QUIC的阻力
tampermonkey这玩意如何替换flash播放器为h5播放器?
Dbutil auxiliary class, manual commit transaction, metadata
tf. Data (II) -- parallelization tf data. Dataset generator
火山引擎云数据库 veDB 在字节内部的业务实践
SAP Spartacus checkout 流程使用 url 粘贴直接跳转到 delivery mode不能打开页面的原因
Today in history: Apple II comes out; Microsoft acquires gecad; The scientific and technological pioneer who invented the word "software engineering" was born
[arcgis] City relevance analysis
[acwing 11. solution number of knapsack problem] 01 knapsack + 01 knapsack + understand the specific meaning of 01 knapsack
Live share experience