Jump to content

[SOLVED] Query name


Canman2005

Recommended Posts

Hi all

 

I have a simple table, which looks like

 

 

id    first_name      surmae

--------------------------

1      david            walker

2      sarah            turner

3      suzy            brick

 

I then have a HTML form which has one input field for "full name".

 

How can I write a select query which allows me to combine the first_name and surname fields of the database and do a full name search

 

hope that make sense, any help would be great

 

thanks

 

dave

Link to comment
Share on other sites

Or, if you are afraid people will post middle names (which you would like to ignore) You could explode() the values, take the first array element and use it as the first name, and the last array element and use it for the last, effectively removing the name from the query. After cleaning the variables you could search for them.

 

For example...

 

$name = explode(' ', $_POST['full_name']);
$firstName = strtolower($name[0]);
$lastName = strtolower($name[count($name) - 1]);

// Clean the first/last name variables here

$query = "SELECT * FROM table WHERE first_name = '{$firstName}' AND surname = '{$lastName}'";

// Query stuff here
?>

 

You get the idea. This matches exact first and last names, if you want it to where they can put in parts of names (tim will return timothy for example) you could do a LIKE query such as the person above me posted.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.