Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search using LIKE

Status
Not open for further replies.

blasterstudios

Technical User
Dec 30, 2004
128
US
I need to pull all records where the First letter of each word in the record begins with the entered variable. Here's my query:
Code:
"SELECT * FROM hgs_contacts WHERE name LIKE '".$_GET['l']."%'";

This only pulls up a record that has 'l' as the first letter. I want it to find it if it's the first or last name. i.e.

l=j
Results:
John Doe
Bob Jones

Any suggestions?
 
are first name and last name stored togethe rin your name field ?

It would probably be best to store them seperately.

"SELECT * from hgs_contacts where first_name like '".$_GET['l']."%' or last_name like '".$_GET['l']."%'"

otherwise i guess something like
"SELECT * from hgs_contacts where name like '".$_GET['l']."%' or name like '% ".$_GET['l']."%'"

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
awesome, that's what i needed. this is for something very basic, so i didn't really need the extra coding for 2 fields there. the one will do just fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top