php - Codeigniter auto-update search with %LIKE% -
i new codeigniter. have done auto suggest search using simple mysql not codeigniter's active records. it's confusing me.
my mysql format :
$s = $_post['s']; $search_result = explode(' ', $s); $query_temp = ''; $i=0; foreach($search_result $search){ $i++; if($i == 1){ $query_temp .= "title '%$search%' or description '%$search%' or keywords '%$search%' or link '%$search%'"; }else{ $query_temp .= "or title '%$search%' or description '%$search%' or keywords '%$search%' or link '%$search%'"; } } $search_query = mysql_real_escape_string(htmlentities($_post['s'])); $run = mysql_query("select * search $query_temp")or die(mysql_error());
but here have search 3 tables. have no idea how in format in codeigniter..
if field 'title' belongs table 'a', field 'description' belongs table 'b' , field 'keywords' belongs table 'c' can use :
$this->db->select('*'); $this->db->from('a, b, c'); $this->db->like(a.title, $search); $this->db->or_like(b.description, $search); $this->db->or_like(c.keywords, $search); $query = $this->db->get();
Comments
Post a Comment