ThinkPHP CURD方法之order方法详解_php实例

WBOY
Release: 2016-06-07 17:18:50
Original
783 people have browsed it

ThinkPHP CURD方法的order方法属于模型的连贯操作方法之一,该方法用于对操作的结果排序

具体用法如下:

$Model->where('status=1')->order('id desc')->limit(5)->select();

Copy after login

注意:连贯操作方法没有顺序,可以在select方法调用之前随便改变调用顺序

支持对多个字段的排序,例如:

$Model->where('status=1')->order('id desc,status')->limit(5)->select();

Copy after login

如果没有指定desc或者asc排序规则的话,默认为asc。

如果你的字段和mysql关键字有冲突,那么建议采用数组方式调用,例如:

$Model->where('status=1')->order(array('order','id'=>'desc'))->limit(5)->select();
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template