Reputation: 2244
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 ...
Upvotes: 1
Views: 1814
Reputation: 434
It should be:
$comma_separated= implode("','", $ids);
$this->db->select("car_id");
$this->db->where_in('car_id',$comma_separated,FALSE); // add FALSE as third parameter
$query_second = $this->db->get_where("car_booking");
It produce:
SELECT
car_id
FROMcar_booking
WHEREcar_id
IN('123','14781')
Upvotes: 2
Reputation: 1680
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");
Upvotes: 1
Reputation: 2168
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");
Upvotes: 2