thinkphp5指定值进行排序和多条件排序

时间:2024-03-30 10:31:40
$contract_types = "2,1,3";
$exp = new \think\Db\Expression('field(contract_type,'.$contract_types.')');
$tpl = Db::name('contract')->order($exp)->select()
//SELECT * FROM `ct_contract` ORDER BY field(contract_type,2,1,3)

thinkphp5指定值进行排序和多条件排序

$contract_types = "2,1,3";
$exp = new \think\Db\Expression('field(contract_type,'.$contract_types.'),create_time DESC');
$tpl = Db::name('contract')->order($exp)->select();
//SELECT * FROM `ct_contract` ORDER BY field(contract_type,2,1,3),create_time DESC

thinkphp5指定值进行排序和多条件排序

其他情况的多条件排序,一样的操作,例:

$tpl = Db::name('contract')->order('contract_type DESC,create_time DESC')->select();
//SELECT * FROM `ct_contract` ORDER BY `contract_type` DESC,`create_time` DESC

thinkphp5指定值进行排序和多条件排序