2013-06-03 46 views
0

郵政值是多選擇,意味着值在陣列的形式來去除反斜槓使用笨的MySQL

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 

,因爲我用破滅功能它會像這樣IN('\'register form \','feedback form \'')我想刪除那些反斜槓。請幫我

+0

尋找的stripslashes? http://php.net/manual/en/function.stripslashes.php – tomexsans

+0

k讓我看看鏈接 –

+0

我已經添加了這樣的新代碼$ test = implode(「','」,$ _ POST ['form_type'] ); \t \t \t $ test1 = stripslashes($ test);它不起作用 –

回答

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