Blogger Information
Blog 65
fans 1
comment 1
visits 119006
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp5 查询自定义排序(按照查询结果顺序排序)
技术宅的博客
Original
4119 people have browsed it
tp5查询数据不排序 会默认asc 升序排序  不能满足项目逻辑需求 
1.首先引入Expression类
use think\db\Expression;
2.排序时准备工作
// 自定义排序
$ids="1,3,2,5,7,9";
$exp=new Expression("field(id,$ids)");
// 查询时
$res=Db::table('table')->whereIn('id',$ids)
   ->order($exp)
   ->select();
这样便可自定义排序


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post