thinkphp in order () How to use the thinkphporder_php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.