How can TP be sorted after query across two tables ??

Source: Internet
Author: User
The data of each table in Table 1 is sorted in descending order. However, if the table in table 2 is updated, the corresponding data in Table 1 is sorted in descending order after TABLE 2 is updated. lilidavetom is arranged in this way. if Table 2 is updated, it is arranged in this way...

The data of each table in Table 1 is sorted in descending order. However, if the table in table 2 is updated, the corresponding data in Table 1 is sorted in descending order after TABLE 2 is updated.lili dave tomIf Table 2 is updatedtom lili dave,tomNo2001But the latest value is2007The result I want is this sorting, but how can this be achieved? How should I write the code in the controller?

$t1=M('table1');$res=$t1->order('time desc')->select();

Reply content:

The data of each table in Table 1 is sorted in descending order. However, if the table in table 2 is updated, the corresponding data in Table 1 is sorted in descending order after TABLE 2 is updated.lili dave tomIf Table 2 is updatedtom lili dave,tomNo2001But the latest value is2007The result I want is this sorting, but how can this be achieved? How should I write the code in the controller?

$t1=M('table1');$res=$t1->order('time desc')->select();

Join can be used for two table join queries.

$Model = M('table1');$Model->join('left join table2 ON table1.name = table2.name')->order('table2.time desc')->select();

TP has a table method and a join method that can be used for multi-table queries.

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.