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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced search with MySQL

Status
Not open for further replies.

Vesku

Programmer
Jun 7, 2000
19
0
0
FI
Hi !


How can i make advanced search with MySQL ?

If i have in STAFF -table value James Smith, how can i find that if i search using searchword 'Smi' or 'jame' ???

I have now code like this:

$query="SELECT * FROM staff WHERE ID = '$searchword' OR Name = '$searchword' OR Email = '$searchword' OR Telephone = '$searchword' ORDER BY Name";



Thx !!
 
A short example

$searchword = "Smi";

$query="SELECT * FROM staff WHERE ID LIKE '$searchword%';

The above would find any record where the ID column starts with "Smi".

$query="SELECT * FROM staff WHERE ID LIKE '%$searchword%';

This would find any record where the ID column contains "Smi" somewhere. The % is like the * wildcard when doing file searches, it can match any number of characters. There are a lot of other operators that let you do more specific things, though.

I can show you a quick way to deal with a specific instance, but I cannot do your homework for you. If you want to use MySQL to even one-fiftieth of its capability, you need to learn some basic SQL.

There are some excellent MySQL tutorials available at Devshed ( and plenty more available at just to name a few. I recommend starting with "Speaking SQL", Parts I and II at Devshed, then browsing around for more sophisticated stuff.

I also recommend the Oreilly book "MySQL and mSQL" for a nice database intro that presents things concisely, without giving you too much to chew on at any one time. (
Have fun learning ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top