php - search a single word in a column -


this 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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -