使用 Zend Framework 进行 LIMIT 和 JOIN
我有 2 个表parent
、children
,关系为 1:M。我需要一个分页。我将 SELECT 与 JOIN 一起使用。对于一位家长,我有一些孩子。如果我尝试设置LIMIT 10
,此查询将总共获得 10 行。但我只需要从表 parent
中获取所有关系的 10 行。我该怎么做?
抱歉我的英语不好。预先感谢您。
Mysql查询:
SELECT `o`.`id` AS `order_id`, `od`.`id` AS `order_destination_id` FROM `order` AS `o`
LEFT JOIN `order_destination` AS `od` ON o.id = od.order_id LIMIT 5
Zend框架:
$select = $this->select()
->setIntegrityCheck(false)
->from(array('o' => 'order'), array('order_id' => 'id'))
->joinLeft(array('od' => 'order_destination'), 'o.id = od.order_id', array('order_destination_id' => 'id'))
->limit(5);
I have 2 tables parent
, children
with relation 1:M. I need a pagination. I use SELECT with JOIN. For 1 parent i have some children. If I try to make LIMIT 10
this query get total 10 rows. But i need to get only 10 rows from table parent
with all relations. How can I do it?
Sorry for my english. Thank you in advance.
Mysql query:
SELECT `o`.`id` AS `order_id`, `od`.`id` AS `order_destination_id` FROM `order` AS `o`
LEFT JOIN `order_destination` AS `od` ON o.id = od.order_id LIMIT 5
Zend framework:
$select = $this->select()
->setIntegrityCheck(false)
->from(array('o' => 'order'), array('order_id' => 'id'))
->joinLeft(array('od' => 'order_destination'), 'o.id = od.order_id', array('order_destination_id' => 'id'))
->limit(5);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道 Zend 框架。这是一个简单的 SQL 解决方案:
I don't know about the Zend Framework. Here a plain SQL solution:
最好使用 Zend_Paginator 对一个表进行分页,然后为每一项请求子项:
It's better to use Zend_Paginator to paginate through one table and then request children for every item: