我相信使用活动记录的Codeigniter中的这一行有错误,但我似乎无法理解第二行中使用IFNULL()和COUNT()的语法。
$this->db->select('places.*, category.*')
->select('IFNULL(COUNT("places_reviews.place_id"), 0) AS num_reviews')
->from('places')
->join('category', 'places.category_id = category.category_id')
->join('places_reviews', 'places_reviews.place_id = places.id', 'left')
->where('places.category_id', $category_id)
->group_by('places.id')
->limit($limit, $offset)
->order_by($sort_by, $sort_order);
发布于 2011-05-10 02:02:40
在SELECT语句后添加false
。CodeIgniter试图用反引号转义语句,但不知道如何正确地进行转义。false
会告诉它不要这样做。
->select('IFNULL(COUNT(`places_reviews.place_id`), 0) AS `num_reviews`', false)
编辑:在COUNT("places_reviews.place_id")
中,引号应该是反引号。
https://stackoverflow.com/questions/5940486
复制相似问题