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 tom
if 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>
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 tom
if 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>
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