使用codeigniter mysql删除查询中的反斜杠

时间:2013-06-03 06:14:02

标签: codeigniter codeigniter-2 codeigniter-url

后置值是多选,意味着值以数组的形式出现

if(!empty($_POST['form_type']))
            {
               $test = implode("','",$_POST['form_type']);
               $this->db->where_in('enquiry.type_of_enquiry',"'".$test."'");
            }

我的查询就像这样

SELECT `sobha_enquiry`.`name`, `sobha_enquiry`.`date_created`, `sobha_enquiry`.`company`, `sobha_enquiry`.`form_of`, `sobha_enquiry`.`projectname`, `sobha_enquiry`.`city`, `sobha_enquiry`.`country`, `sobha_enquiry`.`phone`, `sobha_enquiry`.`type_of_enquiry`, `sobha_enquiryzone`.`enquiry_id`, `sobha_enquiry`.`hearaboutus`, `sobha_enquiry`.`email`, `sobha_enquiry`.`comments`, `sobha_enquiry`.`address`, `sobha_admin`.`id`, `sobha_admin`.`city_id` FROM (`sobha_senquiry`) LEFT JOIN `sobha_enquiryzone` ON `sobha_enquiryzone`.`enquiry_id` =`sobha_enquiry`.`id` LEFT JOIN `sobha_admin` ON `sobha_admin`.`city_id`=`sobha_enquiryzone`.`city_id` WHERE `sobha_enquiry`.`type_of_enquiry` IN ('\'register form\',\'feedback form\'') GROUP BY `sobha_enquiry`.`id` ORDER BY `sobha_enquiry`.`id` desc LIMIT 15

因为我使用了implode函数它就像这样IN('\'寄存器形式\',\'反馈形式\'')我想删除那些反斜杠。请帮帮我

1 个答案:

答案 0 :(得分:1)

$this->db->where_in()将接受数组作为第二个参数。

因此无需破坏数据。

if(!empty($_POST['form_type']))
{
    $this->db->where_in('enquiry.type_of_enquiry',$_POST['form_type']);
}

这将导致,

 WHERE `enquiry`.`type_of_enquiry` IN ('register form','feedback form')

您可以参考此链接了解更多信息,Codeigniter Active Record Documentation