Microsoft
Software
Hardware
Network
Question : Search on multiple keywords
I need to search a database using a single input box.
I already have a search with
$sql = "SELECT * FROM entries WHERE ";
$isSearchByName = isset($_POST["s"]);
$criterion = $_POST["s"];
if ($isSearchByName)
{
$criterion = "FName LIKE '%" . $criterion . "%' OR MName LIKE '%" . $criterion
. "%' OR LName LIKE '%" . $criterion . "%' . OR MaName LIKE '%" . $criterion . "%'";
}
$sql .= $criterion;
The search works great with single entities: "Jos" picks up "Joseph, Josephine, Josten..." etc out of the required fields.
However, when the user makes a simple assumption that involves two terms, like "John Smith", no items are returned, even though they exist in the DB.
Is there a simple, elegant solution, or do I need to have multiple inputs?
Related Solutions:
MySQL Search on multiple keywords
Answer : Search on multiple keywords
If there are more than one term you have first convert string $_POST['s'] to array
$terms = explode(" ", $_POST['s']);
Then you have to iterate in the array building your query using each array value as criterion.
Hope this helps
Random Solutions
Put control inside of AJAX UpdatePanel, now get Type 'System.Web.UI.UpdatePanel
' does not have a public property named 'FileUpload'
How to pause a process execution in C++
Benefits of upgrading from exchange 2003 to Exchange 2010
In Latex, how do I change the format of automatic equation numbering?
PHP, ASP, Moneris
Possible Virus Infection - Can not connect to Internet, Max TCP connections reached.
Stringtopostnet function not working in Crystal viewer 2008 ---
Clearing a submit form once submitted
do i need licenses per user if i buy exchange server?
Problems Replicating SYSVOL and NETLOGON on new DC WS 2008 R2 Standard in 2003 AD