我感到困惑。我正在尝试以下查询:
$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 )
我无论如何都不会这样做。请帮忙
答案 0 :(得分:0)
您可以使用类似
的内容 $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();
输出:
SELECT COUNT(*)AS
numrows
FROMcars
WHEREactive
= 1 ANDid
IN(1,2,3,3)
答案 1 :(得分:0)
尝试这个简单的方法
$query = $this->db->query("SELECT id FROM orders WHERE status = 'Active' AND 3 IN(3,14,2)");
$result = $query->result_array();
return $result;
答案 2 :(得分:0)
试试这个
$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;