我想从列类别的4个单词中提取一个单词。例如,我搜索自助餐,并且自助餐厅将显示餐厅。这是我的代码到目前为止,不幸的是它不工作。
的HomeControllerpublic 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 * FROM restaurants WHERE restoname = '$searchinfo' OR restocuisines = '$searchinfo' OR category = '$searchinfo'";
$result = $this->db->query($sql);
$result = $result->result('array');
return $result;
}
这就是为什么你正常化分贝,像这样 –
不痛数据你可以做'喜欢“%长期%”'类别。您不应将用户输入直接传递给SQL查询。 – chris85