嗨,我在codeigniter中有查询,因为我已经切换到Zend Framework,所以我想在zend framework中进行查询:

这是我的示例查询:

$sql = "SELECT Mes.fromid, Mes.is_read AS is_read, Mes.id AS mesid, Mes.message AS message,
                 max(Mes.date) AS date, User.username AS username, User.id AS Uid
                FROM  `messages` AS Mes
                LEFT JOIN users AS User ON User.id = Mes.fromid
                WHERE Mes.toid = ? AND Mes.fromid <> ?
                GROUP BY Mes.fromid ORDER BY date DESC";

        $query = $this->db->query($sql, array($fromid, $fromid));

        return $query->result();


谢谢你的帮助。

最佳答案

 $sql =  $db ->select()
             ->from('messages as mes',array('fromid','is_read','id as mesid','message','max(date) as date'))
             ->join('users as user','user.id = mes.fromid',array('username','id as uid'))
             ->where('mes.toid = ? ', $toid)
             ->where('mes.fromid = ?', $fromid)
             ->group('mes.fromid')
             ->order('date DESC');

10-06 11:05