tp5.1 随机查询数据
随机查询数据,如果用sql的话 ,直接用 order by rand() 就是说随机排序,我们取多少条都可以,ThinkPHP5从V5.0.17之后,如果排序使用到SQL函数,要用orderRaw(
随机查询数据,如果用sql的话 ,直接用 order by rand() 就是说随机排序,我们取多少条都可以
例:
select * from table where 1 order by rand() limit 10
那tp5.1中如何实现呢?
ThinkPHP5从V5.0.17之后,如果排序使用到SQL函数,要用orderRaw()代替order()进行排序。
示例:
Db::name('user')->orderRaw('rand()')->limit(0,5)->select()
//或者
UserModel::orderRaw('rand()')->limit(0,5)->select()
本文标题: tp5.1 随机查询数据
本文链接: https://crm.yallacn.com/jiaocheng/662.html (转载时请注明来源链接)
本文说明: 有问题或投稿请发送至: 邮箱/service@zhimatong.com QQ/1174742835
特别鸣谢: 如果您觉得本文对您有帮助,请给我们一个小小的赞,收藏本文更利于反复学习哦!



交流群
购物车