Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-31-2002, 12:52 PM   PM User | #1
kjc
New Coder

 
Join Date: Jun 2002
Location: England
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
kjc is an unknown quantity at this point
Need help witha query

Hello,

I am building an e-commerce site for first edition books.
I have a search field which will allow the customer to enter a title or author and then search for matching results.

My database has a field for titile, author firstname, and author surname.

The query at the moment is
"select * from books where Live = 'Y' AND (Title like '%".$searchterm."%' OR Author_Firstname like '%".$searchterm."%' OR Author_Surname like '%".$searchterm."%')"

This works fine when the customer enters a title or just a surname but if they enter both names then this causes a problem.

Is there any way of getting around this...
__________________
Eternity
kjc is offline   Reply With Quote
Old 10-31-2002, 08:26 PM   PM User | #2
mordred
Senior Coder


 
Join Date: Jun 2002
Location: frankfurt, german banana republic
Posts: 1,848
Thanks: 0
Thanked 0 Times in 0 Posts
mordred is an unknown quantity at this point
You could try

Code:
OR CONCAT(Author_Firstname, ' ', Author_Lastname) LIKE '%$searchterm%'
OR CONCAT( Author_Lastname, ' ', Author_Firstname) LIKE '%$searchterm%'
...though that's quick hack if not even worse. The best-suited approach would surely be fulltext indices and trying to use MATCH AGAINST, but my current expertise on these constructs is not very good, so I just point you to the manual:
http://www.mysql.com/doc/en/Fulltext_Search.html
mordred is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:27 AM.


Advertisement
Log in to turn off these ads.