Home > php教程 > php手册 > ThinkPHP中order()方法的使用

ThinkPHP中order()方法的使用

WBOY
Release: 2016-06-01 09:46:50
Original
886 people have browsed it

用法

<code class="language-php">$Model->where('status=1')->order('id desc')->limit(5)->select();</code>
Copy after login

 

注意:连贯操作方法没有顺序,可以在select方法调用之前随便改变调用顺序。
支持对多个字段的排序,例如:

<code class="language-php">$Model->where('status=1')->order('id desc,status')->limit(5)->select();</code>
Copy after login

 

如果没有指定desc或者asc排序规则的话,默认为asc。
如果你的字段和mysql关键字有冲突,那么建议采用数组方式调用,例如:

<code class="language-php">$Model->where('status=1')->order(array('order','id'=>'desc'))->limit(5)->select();</code>
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template