gpt4 book ai didi

codeigniter - Codeigniter 中的多个连接(事件记录)

转载 作者:行者123 更新时间:2023-12-01 13:01:09 25 4
gpt4 key购买 nike

我正在尝试从我的数据库中检索结果,其中包含跨表“地点”、“类别”和“评论”的详细信息,然后按评论数量排序。当我添加第二个连接时,只检索到一行。

$this->db->select('places.*, category.*')
->from('places')
->join('category', 'places.category_id = category.category_id')
->join('places_reviews', 'places_reviews.place_id = places.id')
->where('places.category_id', $category_id)
->limit($limit, $offset)
->order_by($sort_by, $sort_order);

我没有将 IFNULL(COUNT(places_reviews('review_id')) AS 'num_reviews', 0) 添加到 select() 函数中以使代码更清晰。

有什么想法吗?

最佳答案

我想你想要的是LEFT JOIN,试试:

->join('places_reviews', 'places_reviews.place_id = places.id', 'left')

关于codeigniter - Codeigniter 中的多个连接(事件记录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5940241/

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