php - search a single word in a column -
i want fetch 1 word out of 4 words in column category. example search buffet , restaurant has buffet display. code far , unfortunately doesn't work.
homecontroller
public function searchresto(){ $searchinfo = $_post['searchinfo']; $this->load->model('restomodel'); $restaurantinfo['restaurantinfo']=$this->restomodel>searchrestaurant($searchinfo); $this->load->view('pages/searchdisplay',$restaurantinfo); }
restomodel
public function searchrestaurant($searchinfo){ $sql = "select * restaurants restoname = '$searchinfo' or restocuisines = '$searchinfo' or category = '$searchinfo'"; $result = $this->db->query($sql); $result = $result->result('array'); return $result; }
first, sanitize user input. never query database directly user input, may cause sql injection.
after sanatizing user input, try using like
function.
for example:
select 'breakfast, lunch, dinner, buffet, snack' '%lunch%'
output 1.
select 'breakfast, lunch, dinner, buffet, snack' '%nonexistantcategory%'
output 0.
try changing query select * restaurants category '%$searchinfosanatized%'
, $searchinfosanatized
input has been filtered/escaped.
also, believe forgetting -
after restomodel: $restaurantinfo['restaurantinfo']=$this->restomodel>searchrestaurant($searchinfo);
Comments
Post a Comment