Question : How to make a more effective search query?

Experts,

I am trying to make my search function more 'functional' if you will.

I have one search field that you can enter your desired search term.  The search term can be either a series of letters or numbers.

The directions I've created state that you can either search by first or last name, or by what we call Resource ID.  A Resource ID is a series of 7 consecutive digits.

The issue is that I want my search to render more results if you only type in a few letters of either a first or last name, or if you only type in a few numbers of a Resource ID.

I've written the following query which only produces exact results.  Can anyone offer any suggestions on how to make this process produce a more robust set of search results if a search term is not exact?

$sql="SELECT * FROM photos WHERE FirstName LIKE '$search_term' OR LastName LIKE '$search_term' OR EmployeeID LIKE '$search_term'";

Cheers!

Answer : How to make a more effective search query?

You need to add the wildcard character (%) to your SQL string, which will match the search term plus any other characters.


1:
$sql="SELECT * FROM photos WHERE FirstName LIKE '$search_term%' OR LastName LIKE '$search_term%' OR EmployeeID LIKE '$search_term%'";
Random Solutions  
 
programming4us programming4us