PHP从mysql逆序

时间:2015-09-29 01:44:01

标签: php

我有这段代码:

return $this->db->query("SELECT * FROM `messages` where `toid`='$userid' and `fromid`='$userConvensation' or `fromid`='$userid' and `toid`='$userConvensation' order by `id` DESC LIMIT 10");

需要10条最新消息。

但是我需要10条最新消息,但也需要按相反的顺序排列。我怎么能这样做?

输出代码:

foreach($messages->result() as $thisMessage) {
//dostuff
}

2 个答案:

答案 0 :(得分:1)

子查询怎么样:

<TableRow>
<LinearLayout
    android:id="@+id/linearLayout2"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">

    <Button
        android:id="@+id/button1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Button"></Button>
</LinearLayout>

答案 1 :(得分:0)

包装您的查询并重命名并重新排序。

("SELECT * FROM messages` where toid='$userid' and fromid='$userConvensation' or fromid='$userid' and toid='$userConvensation' 
 order by id DESC LIMIT 10") AS latest ORDER BY id ASC