SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Help with search query string

  1. #1
    SitePoint Zealot
    Join Date
    Jan 2002
    Location
    Launceston, Australia
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with search query string

    Hi,

    I am currently using this string for my search results:

    "SELECT * from item WHERE LOWER(name) LIKE LOWER('%$keyword%') OR LOWER(desc1) LIKE LOWER('%$keyword%') OR LOWER(desc2) LIKE LOWER('%$keyword%') OR LOWER(madeof) LIKE LOWER('%$keyword%') OR LOWER(datemade) LIKE LOWER('%$keyword%') OR LOWER(price) LIKE LOWER('%$keyword%')"

    but I was wanting some help in making it work better. I want to be able to search on more than one keyword ie the user enters 'mahogany high chair', I would like my query to return any results with any of these three words in it.

    Also, is it possible to do it so that if someone enters 'chairs' it returns anything with just 'chair' in it???

    Please help - I would appreciate it!

  2. #2
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres somethin ive been messing with, seems to work for me...

    PHP Code:
    $keywords=split("[ ]{1,}"$keyword);
    for(
    $i=0$i<count($keywords); $i++)
    {
    "SELECT * from item WHERE LOWER(name) LIKE LOWER('%$keywords[$i]%') OR LOWER(desc1) LIKE LOWER('%$keywords[$i]%') OR LOWER(desc2) LIKE LOWER('%$keywords[$i]%') OR LOWER(madeof) LIKE LOWER('%$keywords[$i]%') OR LOWER(datemade) LIKE LOWER('%$keywords[$i]%') OR LOWER(price) LIKE LOWER('%$keywords[$i]%')"

    http://redgoals.com ... my site ... nuff said

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you don't need all those LOWER() functions in the query. comparisons in MySQL are case-insensitive by default unless it's a VARCHAR BINARY/BLOB-type column or you are using BINARY in your query.
    - Matt
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

Bookmarks

Posting Permissions

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