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

How does TP sort after querying across two tables? ?

WBOY
Release: 2023-03-03 09:00:02
Original
1217 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template