thinkphp按照父级栏目id数组进行排序输出显示
topid:顶级栏目字段
id:栏目数据表的栏目id
whereIn:用此进行数组条件查询
orderRaw:特殊排序条件
// 栏目首页 列表
public function index()
{
// 顶级栏目排序
$topid = db('arctype')->where('topid',0)->field('id')->order('id asc')->select();
// 定义空数组
$typeid = array();
foreach ($topid as $key => $value) {
$munuid = db('arctype')->where('topid',$value['id'])->field('id')->order('id asc')->select();
$typeid[].= $value['id'];
foreach ($munuid as $key => $value2) {
$typeid[].= $value2['id'];
}
}
$result = db('channeltype')
->alias('a')
->join('arctype c','a.id = c.current_channel')
->where('c.is_del',0)
->whereIn('c.id',$typeid)
->orderRaw("FIELD(c.id, " . implode(',', $typeid) . ")")
->select();
$this->assign('result',$result);
return $this->fetch('lanmu/list');
}
阅读剩余
版权声明:
作者:松跃笔记
链接:https://www.attm.cn/2024/11/06/thinkphp%e6%8c%89%e7%85%a7%e7%88%b6%e7%ba%a7%e6%a0%8f%e7%9b%aeid%e6%95%b0%e7%bb%84%e8%bf%9b%e8%a1%8c%e6%8e%92%e5%ba%8f%e8%be%93%e5%87%ba%e6%98%be%e7%a4%ba/
文章版权归作者所有,未经允许请勿转载。
THE END