Reputation: 133
Post value is multi select, means values are coming in the form of array
if(!empty($_POST['form_type']))
{
$test = implode("','",$_POST['form_type']);
$this->db->where_in('enquiry.type_of_enquiry',"'".$test."'");
}
my query is like this
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
since i used implode function it is coming like this IN ('\'register form\',\'feedback form\'') i want to remove those backslashes . Please help me
Upvotes: 0
Views: 1060
Reputation: 1889
$this->db->where_in()
will accept array as second argument.
So there is no need for imploding the data.
if(!empty($_POST['form_type']))
{
$this->db->where_in('enquiry.type_of_enquiry',$_POST['form_type']);
}
This will result as,
WHERE `enquiry`.`type_of_enquiry` IN ('register form','feedback form')
You can refer this link for more info, Codeigniter Active Record Documentation
Upvotes: 2