0

嗨,我在 codeigniter 中有我的查询,因为我已经切换到 Zend 框架,我想在 zend 框架中进行查询:

这是我的示例查询:

$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();

谢谢你的帮助。

4

3 回答 3

2
$select = $this->select()
            ->setIntegrityCheck(false)
            ->from(
                array('Mes' => 'messages'), 
                array('fromid', 'is_read AS is_read', 'id AS mesid', 'message AS message', 
                    'max(Mes.date) AS date')
            )
            ->joinLeft(array('User' => 'users'), "User.id = Mes.fromid", array('username AS username', 'id AS Uid'))
            ->where('mes.toid = ? ', $toid)
            ->where('mes.fromid = ?', $fromid)
            ->group('mes.fromid')
            ->order('date DESC');

希望这可以帮助 :)

于 2012-09-05T16:21:24.310 回答
2
 $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');
于 2012-09-05T03:32:39.847 回答
0

查看Zend_Db_Statement,看起来您只需进行很少的编辑即可完成这项工作。

可能只是将 Db 适配器更改为 Zend 适配器,它可能会工作。

于 2012-09-05T01:58:33.047 回答