php - search a string in cell -


i have saved different features seperated commas in database shown in image below:enter image description here when select single feature this

select rt.*, rb.*, rf.*, rs.* business rt inner join business_company_info rb on rt.id=rb.business_id inner join business_attributes rf on rt.id=rf.business_id inner join business_basic_info rs on rt.id=rs.business_id business_keyword '%3000%' , features '%feature3%' , status= 0 order rt.id desc 

data fetched database, when have many features failing search. query many features selected

select rt.*, rb.*, rf.*, rs.* business rt inner join business_company_info rb on rt.id=rb.business_id inner join business_attributes rf on rt.id=rf.business_id inner join business_basic_info rs on rt.id=rs.business_id business_keyword '%3000%' , features like'%feature3,feature2,feature4%' , status= 0 order rt.id desc 

this code.

if(isset($_post['advance_search']) && !empty($_post['advance_search']) && ((isset($_post['area']) && !empty($_post['area']))  ||                              (isset($_post['salary']) && !empty($_post['salary'])) || (isset($_post['industry']) && !empty($_post['industry'])) || (isset($_post['jobtype']) && !empty($_post['jobtype']))                              || (isset($_post['keyword']) && !empty($_post['keyword'])) || (isset($_post['empnum']) && !empty($_post['empnum'])) || (isset($_post['year']) && !empty($_post['year']))                              || (isset($_post['features']) && !empty($_post['features'])) || (isset($_post['employ_status']) && !empty($_post['area']))                             )){                                 //echo '<pre>';print_r($_post);exit;                                 $area = $_post['area'];                                 $salary = $_post['salary'];                                 $industry = $_post['industry'];                                 $jobtype = $_post['jobtype'];                                 $keyword = $_post['keyword'];                                 $empnum = $_post['empnum'];                                 $year = $_post['year'];                                  //echo '<pre>';print_r($ids);print_r($salary);print_r($keyword);print_r($jobtype);print_r($industry);exit;                                 //echo '<pre>';print_r($area);print_r($salary);print_r($industry);print_r($jobtype);print_r($keyword);print_r($empnum);print_r($year);exit;                                 /*if(isset($_post['genre'])){                                     $genres_search = implode(',', $_post['genre']);                                 }*/                                 if(isset($_post['employ_status'])){                                     $employment_search = implode(',', $_post['employ_status']);                                 }                                 if(isset($_post['features'])){                                     $features_search = implode(',', $_post['features']);                                 }                                  $conditions = array();                                 if (!empty($area)){                                     $conditions[] = "business_location '%$area%'";                                 }                                 if (!empty($salary)){                                     $conditions[] = "business_salary_rule '%$salary%'";                                 }                                 if (!empty($keyword)){                                     $conditions[] = "business_keyword '%$keyword%'";                                 }                                 if (!empty($jobtype)){                                     $conditions[] = "business_job_type >= '$jobtype'";                                 }                                 if (!empty($industry)){                                     $conditions[] = "business_industries '%$industry%'";                                 }                                 if (!empty($empnum)){                                     $conditions[] = "employees_number '%$empnum%'";                                 }                                 if (!empty($year)){                                     $conditions[] = "established_year '%$year%'";                                 }                                 if (!empty($employment_search)){                                     $conditions[] = "employment_status '%$employment_search%'";                                 }                                 if (!empty($features_search)){                                 $conditions[] = "features '%$features_search%'";                                 }                                  $sql = "select rt.*, rb.*, rf.*, rs.*                                     business rt                                     inner join business_company_info rb                                     on rt.id=rb.business_id                                     inner join business_attributes rf                                     on rt.id=rf.business_id                                     inner join business_basic_info rs                                     on rt.id=rs.business_id                                     ". implode(' , ', $conditions) . " ,                                     status= 0 order rt.id desc"; echo '<pre>';print_r($sql);exit;                             } 

any appreciated. thank you

you can explode $feature , store array. this.

if (!empty($features_search)) {     $feature_array= explode(",", $features_search);     each($feature_array $key => $feature)     {         $conditions[] = "features '%$feature%'";     } } 

hope helped.


Comments