Home >Backend Development >PHP Tutorial >How does TP sort after querying across two tables? ?

How does TP sort after querying across two tables? ?

WBOY
WBOYOriginal
2016-12-05 13:44:131223browse

Every time the data of table1 is queried, it will be sorted in descending order. However, if the table of table2 is updated, the corresponding data of table1 will be sorted in descending order according to the updated data of table2. For example, if it was arranged in reverse order before, lili dave tomif it is arranged like this If table2 is updated, it will be arranged like this tom lili dave. tom will not take the value of 2001 but take the latest value which is 2007. The result I want is sorted like this. But what about What about implementation? How should I write the code in the controller?

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

How does TP sort after querying across two tables? ?

Reply content:

Every time the data of table1 is queried, it will be sorted in descending order. However, if the table of table2 is updated, the corresponding data of table1 will be sorted in descending order according to the updated data of table2. For example, if it was arranged in reverse order before, lili dave tomif it is arranged like this If table2 is updated, it will be arranged like this tom lili dave. tom will not take the value of 2001 but take the latest value which is 2007. The result I want is sorted like this. But what about What about implementation? How should I write the code in the controller?

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

How does TP sort after querying across two tables? ?

Join can be used for related queries between two tables.

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

TP has a table method and a join method that can query multiple tables

Statement:
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