搜索一个单词,就像我在codeigniter中的文本框中给出的不完全一样

时间:2016-05-23 04:57:50

标签: php mysql codeigniter

我使用codeigniter中的模型从我的数据库中搜索一个单词。我完成了搜索确切的单词搜索。但是当我给出部分词语时,我还需要找到一个词。我使用LIKE子句搜索一个单词。但我不知道如何在我的模型函数中使用LIKE%子句。

型号:

public function get_search() {
  $match = $this->input->post("search");
  $match1 = $this->input->post("search1");
  $match2 = $this->input->post("search2");
  $match3 = $this->input->post("search3");
  $match4 = $this->input->post("search4");
  $match5 = $this->input->post("search5");
  $match6 = $this->input->post("search6");
  $this->db->query("SELECT * FROM patient_creation;");
  $this->db->where("patient_id like '$match' OR mobile like '$match1' OR name like '$match2' OR fathername like '$match3' OR address like '$match4' OR created BETWEEN '$match5' AND '$match6'");
  //$this->db->or_where("name LIKE '".$match2."%'"); 
  $query = $this->db->get("patient_creation");
  return $query->result();
}

我需要LIKE%搜索$ match2,$ match3和$ match4变量。

3 个答案:

答案 0 :(得分:0)

更改:

$this->db->where("patient_id like '$match' OR mobile like '$match1' OR name like '$match2' OR fathername like '$match3' OR address like '$match4' OR created BETWEEN '$match5' AND '$match6'");

$this->db->where("patient_id like '".$match."' OR mobile like '".$match1."' OR name like '".$match2."' OR fathername like '".$match3."%' OR address like '".$match4."%' OR created BETWEEN '".$match5."' AND '".$match6."'");

答案 1 :(得分:0)

注意pip install ujson中的分号准备查询字符串并在查询函数中使用,如

SELECT * FROM patient_creation;

答案 2 :(得分:0)

public function get_search() {
  $match = $this->input->post("search");
  $match1 = $this->input->post("search1");
  $match2 = $this->input->post("search2");
  $match3 = $this->input->post("search3");
  $match4 = $this->input->post("search4");
  $match5 = $this->input->post("search5");
  $match6 = $this->input->post("search6");
  $this->db->select("*");
  $this->db->like("patient_id" ,$match);
  $this->db->or_like("name" ,$match2);
  $this->db->or_like("fathername" ,$match3);
  $this->db->or_like("address" ,$match4);
  $this->db->or_like("name" ,$match2);
  $this->db->where('created  >=', $match5);
  $this->db->where('created  <=', $match6);
  $query = $this->db->get("patient_creation");
  return $query->result();
 }