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 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了