gpt4 book ai didi

php - 如何在 Zend Framework 中连接表?

转载 作者:太空宇宙 更新时间:2023-11-03 11:05:22 25 4
gpt4 key购买 nike

嗨,我在 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');

关于php - 如何在 Zend Framework 中连接表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12273493/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com