Home > php教程 > php手册 > ThinkPHP CURD方法之order方法详解

ThinkPHP CURD方法之order方法详解

WBOY
Release: 2016-06-06 20:21:32
Original
1288 people have browsed it

ThinkPHP CURD方法的order用于对操作的结果排序。这篇文章主要介绍了order方法的用法,需要的朋友可以参考下

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

具体用法如下:

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

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

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

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

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

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

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

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template