我有一段代码:

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
}

最佳答案

子查询如何:

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

10-05 21:33