Re: Struggling with MySQL query
| From: | Andrew Ballard | Date: | Tue, 09 Aug 2011 14:54:52 +0000 |
| Subject: | Re: Struggling with MySQL query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-314448@lists.php.net to get a copy of this message | ||
On Tue, Aug 9, 2011 at 10:14 AM, David Green <simpill@gmail.com> wrote:
[snip]
> $data = mysql_query("SELECT * FROM news_items WHERE upper('headline') LIKE
> '%$find%'");
A couple things to consider.
First, as a few others have pointed out, you probably want to remove
the single quotes around the word headline in your query. The quotes
cause the query to compare the wildcard string '%{$find}%' to the
literal string 'headline' instead of the contents of a column named
headline. That would cause your query to return either no results for
ordinary search terms, or else return the entire table if the value of
$find is the word 'headline' or any sequence of characters within that
word.
You also probably don't need upper(...) function at all. Unless you
used a case-sensitive collation for that column/table (or are storing
it as binary data rather than text) the condition
'My Article Title' LIKE '%article%'
would return a match even though the case is different.
Andrew