我感到困惑。我正在尝试以下查询:
$this->db->select('id')->from("orders")->where("status", "Active")->where_in($this->session->id, $this->db->query("SELECT `associated_staffs` FROM `orders` WHERE `status`='Active'")->result());
$total_rows = $this->db->count_all_results();
它生成以下 sql 查询:
SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(, )
但它应该生成:
SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(3,14,2 )
无论如何,我都不知道该怎么做。请帮忙
你可以
使用类似的东西
$this->db->where(array('active' => 1));
$this->db->from('cars'); //table name here
$this->db->where_in('id', array(1, 2, 3, 3)); //pass yoru where_in values here
$cars = $this->db->count_all_results();
echo $cars;
echo $this->db->last_query();
输出::
选择 COUNT(*( 作为
numrows
从cars
,其中active
= 1 和id
IN(1, 2, 3, 3(
试试这个简单的方法
$query = $this->db->query("SELECT id FROM orders WHERE status = 'Active' AND 3 IN(3,14,2)");
$result = $query->result_array();
return $result;
试试这个
$this->db->select('COUNT(*) AS numrows');
$this->db->from('orders');
$this->db->where_in(3,array(3,14,2));
$this->db->where('status','Active');
$query=$this->db->get();
$result=$query->row();
echo $result->numrows;