GPA
GPA

Reputation: 111

Search condition using php,sql

I try to create search system using php and sql current condition is working fine but if I want to search for John Doe (firstname + lastname) nothing happens. I try the + between firstname and lastname but it did not work.

Condition is here:

 if(isset($_POST["query"])){
   $search = mysqli_real_escape_string($conn, $_POST["query"]);
   $query = "
   SELECT * FROM users
   WHERE firstname LIKE '%".$search."%'
   OR lastname LIKE '%".$search."%'
 ";
}

Upvotes: 0

Views: 82

Answers (1)

The Alpha
The Alpha

Reputation: 146201

You msy try something like this (using CONCAT):

$query = "SELECT * FROM users
WHERE firstname LIKE '%".$search."%'
OR lastname LIKE '%".$search."%'
OR CONCAT(firstname,' ', lastname) LIKE '%".$search."%'";

Upvotes: 2

Related Questions