zero-perfoliate
zero-perfoliate

Author Topic: MYSQL Search Records  (Read 187 times)

Offline mattloto

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
MYSQL Search Records
« on: August 05, 2010, 12:12:12 PM »
I am making a web site for my class for a lost&found database.  I have everything set up, and it all works, but I was wondering how I could set up a search function to check mysql records for something.  I was thinking of using the WHERE ending to the mysql query, but that would only return exact matches.  Is there like a wild-card for the WHERE ending?  Thanks in advance

Offline collegemike

  • PHP Workers
  • **
  • Posts: 5
  • Karma: +0/-0
Re: MYSQL Search Records
« Reply #1 on: August 06, 2010, 09:17:05 PM »
mattloto,

If you're searching out particular records you'd use the WHERE command. By default if you leave off WHERE it matches all records (like the wildcard (*) character).

If I misunderstood your question, could you please explain it in a little more detail, perhaps giving examples of the kind of queries you want to do? Showing some code might help myself and others track down a solution.

-Mike

Offline TinMonkey

  • PHP Workers
  • **
  • Posts: 5
  • Karma: +0/-0
Re: MYSQL Search Records
« Reply #2 on: August 07, 2010, 02:09:52 AM »
the simplest way to search in mysql is by using LIKE.
For example:

Code: [Select]
SELECT * FROM `Items` WHERE `Item_Desc` LIKE '%pen%'
this will return anything that has the word pen in it.. like pens or open or ball point pen, etc.. The percent signs are serving as a wildcard to tell the query to match pen reguardless of what comes before or after it. you of course would replace pen with the escaped search term.

Enjoy.