Skip to main content
Inspiring
March 12, 2009
Question

First, Middle, and Last name search box

  • March 12, 2009
  • 4 replies
  • 1799 views
Hey everyone,
Does anyone know how to be able to search on all 3 fields for a First Name, Middle Name, and a Last Name all in the same search box? I am able to do this now, but the problem is if there are 2 words in a last name, such as "La Rue", the search can't find this. The only way I know how to make this work is to do a search on each field separately, but we want to be able to search for all 3 fields in one search box. Does anyone know how to do this? I have attached the 2 different types of code for searching in one box, or searching in 3 boxes that we already have. Thanks.

Andy
    This topic has been closed for replies.

    4 replies

    Inspiring
    March 30, 2009
    Change your form so that the user is specifying which name is which.
    Participating Frequently
    March 30, 2009
    Sorry for the delayed response; the answer to the problem my psuedo-code didn't catch would be to add in one more case - if three strings exist match against two separate cases, one case in which string1 and string2 are matched against the first name, and the second case is where string2 and string3 are matched against the last name...plus the obvious case in which string1 is matched against first, string2 matched against middle, and string3 matched against last.
    Inspiring
    March 16, 2009
    Fetch wrote:
    > Four Strings (i.e. two middle names)
    >

    It is just as likely that it is two word first name ("Mary Sue") or a
    multiple word last name ("Von Der LongName") as it is middle names.
    Inspiring
    March 16, 2009
    I have updated the code with what I have attached below. I can search for a last name such as "La Rue" and find the person. But if I type in "Don La Rue", it won't work. How do I do this with searching for all these instances with each field that may have 2 names in each field?
    Participating Frequently
    March 16, 2009
    The simplistic way to do this would be to have your code check the number of space-delimited strings entered, then base the search of that number. Like this:

    One String (i.e. user likely inputted a first OR last name like James, or Price)
    - search against first and last name in db

    Two Strings (i.e. user likely inputted a full name like James Price)
    - search first string against first name field AND/OR last name against last name field

    Three Strings (i.e. user likely inputted a first, middle, and last name like James Terry Price)
    - search first string against first name field AND/OR last name against last name field AND/OR middle name against middle name field

    Four Strings (i.e. two middle names)
    - the code here is the most tricky...first you need to do some fancy trimming to break it up into the three chunks you need, with the two 'middle' strings comprising the middle name, and then do your searches 'as normal'.

    Hope this helps!