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

Thread: search code

  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation search code

    PHP Code:
    $GetListNews "SELECT * FROM news WHERE title LIKE '%$searchQuery%' OR copy LIKE '%$searchQuery%' OR teaser LIKE '%$searchQuery%' AND year = '$date' ORDER BY id desc"
    Hi, please can someone tell me why the above code does not work.

    Basically I submit a key word, and this script is supposed to pull out the rows of data that has the keyword within 3 of the fields (title, copy and teaser).
    This works. But I want to narrow it down further. Each entry has a filed "year" in which it says 2003, 2004, 2005 etc etc etc

    For some reason when this search is submitted is pull out all the rows of data with the correct keywords but it completly ignores the last bit of the query
    PHP Code:
    AND year '$date' 
    However the following works:
    PHP Code:
    $GetListNews "SELECT * FROM news WHERE year = '$date' ORDER BY id desc"
    so I think there is some sort of error with the last part of the query integrated at the same time with the parts which search (like) keywords.

  • #2
    New Coder
    Join Date
    Oct 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $GetListNews "SELECT * 
                      FROM news 
                     WHERE year = '"
    .mysql_escape_string($date)."' 
                       AND (title LIKE '%"
    .mysql_escape_string($searchQuery)."%' OR 
                            copy LIKE '%"
    .mysql_escape_string($searchQuery)."%' OR 
                            teaser LIKE '%"
    .mysql_escape_string($searchQuery)."%')  
                  ORDER BY id DESC"



  •  

    Posting Permissions

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