View Single Post
Old 11-13-2012, 07:33 AM  
Tent Pitcher
Confirmed User
 
Tent Pitcher's Avatar
 
Industry Role:
Join Date: Nov 2012
Location: New Orleans
Posts: 213
Quote:
Originally Posted by Ketchup View Post
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.
__________________
Tent Pitcher - Adult Search Engine

Last edited by Tent Pitcher; 11-13-2012 at 07:44 AM..
Tent Pitcher is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook