I created a search function in my website that is able to search across all columns. In my accounts table, I have accounts wherein they have their first name and last name. If I search for John, it shows all results, and if I search for Smith, it also shows them. However, I cannot search for John Smith. I tried to concatenate two columns but I get errors.
Controller:
function search_homeowner($searchquery)
{
$this->db->select('*')->from('accounts');
$this->db->where('(role= 0 AND isActive= 1)',NULL,FALSE);
$this->db->where('(CONCAT(firstname, ' ', lastname) LIKE "%'.$searchquery .'%" OR firstname LIKE "%'.$searchquery .'%" OR lastname LIKE "%'.$searchquery .'%" OR username LIKE "%'.$searchquery .'%" OR address LIKE "%'.$searchquery .'%" )',NULL,FALSE);
$query = $this->db->get();
print_r($this->db->last_query());
if($query->num_rows() > 0)
{
return $query->result();
}
else
{
return $query->result();
}
}`
The code above gives me an error:
Parse error: syntax error, unexpected '', lastname) LIKE "%'' (T_CONSTANT_ENCAPSED_STRING) in C:\xampp\htdocs\pgevCI\application\models\model_accounts.php on line 119