Quote:
Originally Posted by Ketchup
I have a search form that when people type in the exact name of the user it shows results but if they don't add a space inbetween first and last names or they do and that is not the name it won't show results.
Such as John Doe shows results but not Johndoe
Can I change this code below to show results for johndoe as well?
Code:
if(isset($_POST['search']))
{
$searchs = array();
if(!empty($_POST['contactname']))
{
$searchs[]="contactname LIKE '%".$_POST['contactname']."%'";
}
|
Without modifying your data structure, you are probably going to want to create a temp table to hold the contact names from the database without spaces:
Code:
SELECT id, REPLACE(contactname, ' ', '') AS tmp FROM table WHERE tmp = '%' . $_POST['contactname'] . '%'
Once you have called that query, you can query $_POST['contactname'] with the spaces removed against that instead. The problem is that the code you provided is creating an array of query stubs, so without seeing the full query being called I can't tell you how better to integrate the temp table query. There are more efficient ways to do things, but not without changing the table structure.