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

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 07-25-2007, 02:52 PM   PM User | #1
space cowboy
New Coder

 
Join Date: Jun 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
space cowboy is an unknown quantity at this point
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.
space cowboy is offline   Reply With Quote
Old 07-25-2007, 03:43 PM   PM User | #2
mattis2k
New Coder

 
Join Date: Oct 2005
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
mattis2k is an unknown quantity at this point
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"

mattis2k 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 10:31 AM.


Advertisement
Log in to turn off these ads.