Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search function not displaying results for both names

Posted on 2013-06-19
3
Medium Priority
?
257 Views
Last Modified: 2013-06-19
I have a search function where you can search someones name. The first name and surname are in different database columns so i'm using this...

WHERE fname LIKE '%$search%' OR lname LIKE '%$search%'

It's not working though. Say for example 'John Smith' is one of the searchable names. If you search 'John' or 'Smith' he displays for if you search 'John Smith' he doesn't.

Any idea how I can get this too work?
0
Comment
Question by:BrighteyesDesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:Robert Saylor
ID: 39260115
what you have to do is 1st remove the space from your search string then concat the two fields and do a like search.
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39260117
Split the name so you can add them separately to the sql
Your current sql requires the column/s contain john smith exactly in either column (and ignore anything before or after the term in the column.)
Or use CONCAT
WHERE CONCAT(fname,' ',lname) LIKE '%$search%'
Though you probably don't want the wild card for this method unless there are other names, e.g. middle names
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39260151
Another possibility...

WHERE fname LIKE '%$search%' OR lname LIKE '%$search%' OR CONCAT(fname,' ',lname) LIKE '%$search%'
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question