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
https://forums.phpfreaks.com/topic/117898-solved-query-name/
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
https://forums.phpfreaks.com/topic/117898-solved-query-name/#findComment-606471
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.