dongtaochan0777 2016-12-29 07:33
浏览 18
已采纳

如何删除codeigniter的where条件中的斜杠

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 ...

  • 写回答

2条回答 默认 最新

  • douchengchen7959 2016-12-29 07:37
    关注

    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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网