public function count_category_images($p_id)
{
$this->db->select('gallery.*','category.category_name');
$this->db->join('category', 'category.id = gallery.category_id');
$this->db->order_by('gallery.id','desc');
$this->db->where('category.id',$p_id);
return $this->db->count_all_results('gallery');//line no 81
}
我收到此错误
错误号码:1054未知列'数组'在' where子句'
SELECT
COUNT(*) AS `numrows`
FROM
`gallery`
JOIN `category` ON `category`.`id` = `gallery`.`category_id`
WHERE
`category`.`id` = `Array`
ORDER BY
`gallery`.`id` DESC
文件名:C:/wamp64/www/rox/application/models/roxmodel.php
行号:81
答案 0 :(得分:0)
我的 $ p_id 是一个数组。在通过 $ p_id 之前,只需回显并测试 $ p_id 的值
在你的where子句中, category
。id
应该等于某个值,而不是数组。
答案 1 :(得分:0)
您需要“where_in”而不是现有的“where”。我认为codeigniter的工作原理如下:
$this->db->where_in('category.id',$p_id);
编辑:更具体:where_in将根据您的参数,模型和意图创建以下内容,我可以看到:
SELECT
COUNT(*) AS `numrows`
FROM `gallery`
JOIN `category` ON `category`.`id` = `gallery`.`category_id`
WHERE `category`.`id` IN ('1', '2', '3')
ORDER BY `gallery`.`id` DESC