当前位置:网站首页>三级分类展示
三级分类展示
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);
}
}
}
边栏推荐
- After five years of losing the lawsuit, the trillion reptile army is ready to move
- How to write high-performance code (IV) optimize data access
- 中国 SaaS 发展落后美国 10 年,仍需借助创新、开源、并购等策略发力 | ArchSummit
- Introduction to long connection
- Explain in detail the differences between real participation formal parameters in C language
- 五年官司终败诉,万亿爬虫大军蠢蠢欲动
- Hashicopy之nomad应用编排方案06(配置task)
- Using vscode code code template to improve mobx coding efficiency
- [bug resolution] after uploading the image, cancel the upload and upload again. The last image still exists
- C# 设置窗体和系统的光标形状
猜你喜欢

NFT市场怎么样 为什么NFT能如此火爆 怎么搭建NFT平台

31W contest question bonus! When AI for Science collides with the "pilot Cup", what sparks will be generated?

两件小事,感受到了和大神的差距
Go语言学习之WaitGroup用法详解

为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
![[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]](/img/1a/7b80f3d81c1f4773194cffa77fdfae.png)
[filter] design of time-varying Wiener filter based on MATLAB [including Matlab source code 1870]

如何写出高性能代码(四)优化数据访问

长连接简介

关于uni-app 配置 APP 不显示顶部标题栏设置

微软再曝“丑闻”:在办公室看 VR 黄片,“HoloLens 之父”即将离职!
随机推荐
Go 如何减少供应链攻击?
QUIC的阻力
How does Cassandra, an open source database giant, tell a "new story" in China? Face to face
SAP Spartacus checkout process uses URL paste to directly jump to delivery mode. Why the page cannot be opened
[problem summary] $t
看不懂Kotlin源码?从Contracts 函数说起~
On the life extension of distributed locks -- redis based distributed locks
021(Keywords Search)(AC自动机)
Terraformer导入云上资源
Unity detects whether the object is within the viewing cone of the camera
使用华为HECS云服务器打造Telegraf+Influxdb+Grafana 监控系统【华为云至简致远】
[backtrader source code analysis 46] cerebro Py code comments (boring, one of the core backtrader codes, recommended for reading, comments for reference only)
历史上的今天:Apple II 问世;微软收购 GECAD;发明“软件工程”一词的科技先驱出生...
关于#php#的问题:php写的原来的部署环境是在phpstudy里面进行部署的,php+MySQL+Apache但是由于每次都得保证电脑开着
live share使用体验
为什么每运行一部都显示一次数据库已存在,都要删除数据库,然后才能成功,每运行一部都要删除一次数据库,重新运行整体才成功.
Live share experience
Unity 检测对象是否在相机的视锥体范围内
论文导读 | 机器学习在数据库基数估计中的应用
从QUIC到TCP