こんにちは、私はCodeigniterで求人検索プロジェクトを作ってCIを学ぼうとしています。私はそれに複数の入力フィールドジョブの検索エンジンを作ろうとしています。フォームには3つのフィールドがあります。
class Search extends CI_Controller{
public function normal(){
$this->form_validation->set_rules('job_keywords', 'Job Keywords', 'required');
if($this->form_validation->run() == FALSE){
$viewdata['main_view'] = 'home';
$this->load->view('layout/main', $viewdata);
}
else{
$search_term = $this->input->post('job_keywords');
$location = $this->input->post('job_location');
$type = $this->input->post('job_type');
$searchdata['search_results'] = $this->search_model->default_search($search_term, $location, $type);
$searchdata['main_view'] = 'search_page';
$this->load->view('layout/main', $searchdata);
}
}
}
私のモデルは次のとおりです:
public function default_search($search_term, $location="", $type){
$searchterm = $search_term;
$this->db->like('job_title', $searchterm);
$this->db->or_like('job_description', $search_term);
$this->db->where('type_id', $type);
if($location!= ""){
$this->db->like('location_id', $location);
}
$res = $this->db->get('jobs');
if($res->num_rows() >= 1){
return $res->result();
}
else{
return false;
}
}
私はちょうど使用しているとき、私は、検索結果を取得しています私のフォームは私のコントローラのコードはこれです Form screenshot
を下回っています$ this-> $ db-> like()と$ this-> $ db-> or_like()ですが、$ this-> $ db-> where()を使用しているときは、WHERE句の後にクエリーが続きません。 $ this-> $ db-> or_like()を削除すると、うまく動作しますが、2つのlike節では動作しません。誰かが私が間違っているところを教えてもらえますか?ありがとうございました。
Job table structure with 2 rows of data
私は、データベースに2つの列を比較していますもう一つフォームの私の最初のフィールド。場所フィールドはオプションです。 –
このように最後に実行されたクエリを表示しようとします。 'echo $ this-> db-> last_query();' – KubiRoazhon
私はこれを取得しています - SELECT * FROM 'jobs' WHERE' job_title' LIKE '%frontend%' ESCAPE '!' OR 'job_description' LIKE '%フロントエンド%' ESCAPE '!' AND 'type_id' = 'pt' –