Jump to content


Photo

like command


  • Please log in to reply
3 replies to this topic

#1 gurechan

gurechan
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 August 2006 - 01:24 PM

Hi, I'm trying to set up a search form and using the LIKE command in MySQL, ie:

SELECT * FROM books WHERE title LIKE '%$search%'

Now say I have a heap of books that have the work book in the title, this query works fine if you enter book in the search field, but if you enter books you get no results.

Is there an easy way to get it to still find a match.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 August 2006 - 01:43 PM

http://mysql.com/doc...n-matching.html

SELECT * FROM books WHERE title LIKE '$search%'
Legend has it that reading the manual never killed anyone.
My site

#3 gurechan

gurechan
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 August 2006 - 01:54 PM

Yeah, I've seen and tried that. Still has the same result tho.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 09 August 2006 - 02:08 PM

Nope -- there's no easy way; you can hack and remove the trailing "s" and try the query again, but it's kludgy at best.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users