Detailed Explanation of order Method of ThinkPHP CURD Method

  • 2021-07-01 06:53:55
  • OfStack

The order method of the ThinkPHP CURD method belongs to one of the coherent operation methods of the model, which is used to sort the results of the operation.

The specific usage is as follows:


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

Note: Coherent manipulation methods have no order, so you can change the invocation order at will before the select method is called.

Supports sorting of multiple fields, such as:


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

If no desc or asc collation is specified, the default is asc.

If your field conflicts with the mysql keyword, it is recommended to call it in array mode, such as:


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


Related articles: