I am using in array in where conditions of Codeigniter.
But here I am not getting the exact result what I need actually ,here in where condition some slashes are adding . Below is my code
$comma_separated= implode("','", $ids); // here i am getting ids
$this->db->select("car_id");
$this->db->where_in('car_id',array(stripslashes($comma_separated)));
$query_second = $this->db->get_where("car_booking");
My last query is
SELECT `car_id`
FROM `car_booking`
WHERE `car_id` IN('123\',\'14781')
Here stripslahses is not working in the where conditions .
Any suggestion ,thank you ...
You cannot apply string functions to array. The below code might help you to solve your problem.
$this->db->select("car_id");
foreach ($comma_separated as $key=>$value) {
$comma_separated[$key] = stripslashes($value);
}
$this->db->where_in('car_id',array(stripslashes($comma_separated)));
$query_second = $this->db->get_where("car_booking");
After your question edited, you no need to pass $ids array into $this->db->where_in
. So use this code will solve your problem.
//$comma_separated= implode("','", $ids); // here i am getting ids
$this->db->select("car_id");
$this->db->where_in('car_id', array_map('stripslashes',$ids)); // incase you want to use stripslashes
$query_second = $this->db->get_where("car_booking");
Change from
$this->db->select("car_id");
$this->db->where_in('car_id',array(stripslashes($comma_separated)));
$query_second = $this->db->get_where("car_booking");
to
$this->db->select("car_id");
$this->db->where_in('car_id',array_map('stripslashes',$ids));
$query_second = $this->db->get_where("car_booking");