Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    kjc
    kjc is offline
    New Coder
    Join Date
    Jun 2002
    Location
    England
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •