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条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备