Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,602 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 946 people online right now. Registration is fast and FREE... Join Now!




Mysql Search

 
Reply to this topicStart new topic

Mysql Search

Dr. Tim
post 26 Oct, 2002 - 04:46 PM
Post #1


D.I.C Addict

****
Joined: 20 Mar, 2002
Posts: 993

How do I do it?
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 26 Oct, 2002 - 06:19 PM
Post #2


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 2 times

Dream Kudos: 228
My Contributions


SQL
SELECT * FROM table WHERE item LIKE '%$variable%'


where the variable is you can do
%$variable will find the stuff that begins with $variable
$variable% will find the stuff that ends with $variable
or
%variable% will find the stuff that contains $variable
User is offlineProfile CardPM

Go to the top of the page

Dr. Tim
post 16 Nov, 2002 - 05:04 PM
Post #3


D.I.C Addict

****
Joined: 20 Mar, 2002
Posts: 993

Thank you.
User is offlineProfile CardPM

Go to the top of the page

Cookie Mobster
post 16 Nov, 2002 - 05:41 PM
Post #4


nooneenooneenooonee

Group Icon
Joined: 12 Oct, 2001
Posts: 4,723



Dream Kudos: 18
My Contributions


Or if you want a more robust method try using MySQL 3.23.23's fulltext indexing search.

Add the following to the end of your table creation or alteration statement.
SQL
FULLTEXT(field1,field2,...)

And then use the Match and against functions in your select query:
SQL
WHERE MATCH (field1,field2,...) AGAINST ('text to search for');

If you want to do binary searches (like the real search engines do you can do it simply with this method (the one below searches for Sam without McKone):
SQL
WHERE MATCH (field1,field2,...) AGAINST ('+Sam -Mckone' IN BOOLEAN MODE);

One small inportant note is that if the phrase you are looking for is found in more than 50% of the rows in your table it will return 0 results to avaid bogging down your server and decrease irrelavent searches...
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 02:10AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month