Thinkphp in the order () use of the detailed method, Thinkphporder
This article describes the use of the order () method of thinkphp. The order method can be used to sort the results of a database operation. That is, the clause that is an order by in the SELECT statement.
The order method belongs to one of the model's coherent operations, and is used to sort the results of the database operation. That is, the clause that is an order by in the SELECT statement.
Usage
$Model->where (' Status=1 ')->order (' id desc ')->limit (5)->select ();
Note: There is no order for coherent operations, and you can arbitrarily change the order of calls before the Select method is called.
Support for sorting multiple fields, for example:
$Model->where (' Status=1 ')->order (' id desc,status ')->limit (5)->select ();
If you do not specify DESC or ASC collation, the default is ASC.
If your field is conflicting with the MySQL keyword, it is recommended to use an array method, such as:
$Model->where (' Status=1 ')->order (Array (' order ', ' id ' = ' desc '))->limit (5)->select ();
Add:
Thinkphp cannot use->order () to sort the two solutions!
Using thinkphp, you find that you cannot use->order ($order) to sort.
$order = "Info.date2 desc";
It is a pity that the result order has become order by Date2 limit ... desc is gone.
Solution One:
$order there can be no space on either side, $order = "Info.date2 desc"; (correct). $order = "Info.date2 desc"; (Error!) )
Solution Two:
Open File: D:\WebSite\Zbphp.com\www\ThinkPHP\Extend\Model\ViewModel.class.php
Modify line 136th, change to $array = explode (', trim ($order)), plus trim Save:
The second method is recommended, but look forward to the Thinkphp official website can fix this small problem, lest the user to modify the kernel code
About thinkphp in order () use the method to introduce you so much, I hope to help you, at the same time also very much thank you to help the home site support!
http://www.bkjia.com/PHPjc/1122897.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122897.html techarticle thinkphp The Order () method in detail, Thinkphporder This article describes the use of the thinkphp order () method. The order method can be used to sort the results of a database operation. That is the equivalent of ...