[英]codeigniter database where_in error
I am getting confused. 我很困惑。 I am trying below query: 我正在尝试以下查询:
$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();
It is generating below sql query: 它在sql查询下生成:
SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(, )
but it should generate: 但它应该生成:
SELECT COUNT(*) AS `numrows` FROM `orders` WHERE `status` = 'Active' AND 3 IN(3,14,2 )
I am not getting anyway how to do it. 无论如何我都没有怎么做。 Please help 请帮忙
You can use something like 您可以使用类似
$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();
output:: 输出:
SELECT COUNT(*) AS
numrows
FROMcars
WHEREactive
= 1 ANDid
IN(1, 2, 3, 3) 选择COUNT(*)numrows
从active
cars
= 1 ANDid
IN(numrows
)
Try this simple method 试试这个简单的方法
$query = $this->db->query("SELECT id FROM orders WHERE status = 'Active' AND 3 IN(3,14,2)");
$result = $query->result_array();
return $result;
Try this 尝试这个
$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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.