You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'name_product LIKE '%น้ำ%'OR search1 LIKE '%น้ำ%'OR search2 LIKE '%' at line 134
public function getnameproduct($searchTerm){
$terms = explode(" ",$searchTerm);
$query = "SELECT * FROM tb_product WHERE ";
foreach ($terms as $each){
$i=0;
$i++;
if ($i == 1)
$query .= "name_product LIKE '%".$each."%'";
else
$query .= "OR product_detail LIKE '%".$each."%'";
$query .= "OR search1 LIKE '%".$each."%'";
$query .= "OR search2 LIKE '%".$each."%'";
$query .= "OR search3 LIKE '%".$each."%'";
$query .= "OR search4 LIKE '%".$each."%'";
$query .= "OR search5 LIKE '%".$each."%'";
$query .= "OR search6 LIKE '%".$each."%'";
$query .= "OR search7 LIKE '%".$each."%'";
$query .= "OR id_product LIKE '%".$each."%'";
}
$query .= "ORDER BY name_product ASC";
$result = $this->db->select($query);
return $result;
}
$query .= " OR product_detail LIKE '%".$each."%'
OR search1 LIKE '%".$each."%'
OR search2 LIKE '%".$each."%'
OR search3 LIKE '%".$each."%'
OR search4 LIKE '%".$each."%'
OR search5 LIKE '%".$each."%'
OR search6 LIKE '%".$each."%'
OR search7 LIKE '%".$each."%'
OR id_product LIKE '%".$each."%' ";
public function getnameproduct($searchTerm){
$query_string = "SELECT * FROM tb_product WHERE ";
$display_words = "";
$keywords = explode(' ', $searchTerm);
foreach($keywords as $word){
$query_string .= " name_product LIKE '%".$word."%' OR product_detail LIKE '%".$word."%' OR search1 LIKE '%".$word."%' OR search2 LIKE '%".$word."%' OR search3 LIKE '%".$word."%' OR search4 LIKE '%".$word."%' OR search5 LIKE '%".$word."%' OR search6 LIKE '%".$word."%' OR search7 LIKE '%".$word."%' OR id_product LIKE '%".$word."%' OR ";
}
$query_string = substr($query_string, 0, strlen($query_string) - 3);
$result = $this->db->select($query_string);
return $result;
}