RE: Struggling with MySQL query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Or the query should look like this, if there is a 'headline' field:

UPPER(`headline`) LIKE '%".mysql_real_escape_string(trim(strtoupper($find)))."%'

Cheers,

	Tamas

-----Original Message-----
From: Andrew Ballard [mailto:aballard@xxxxxxxxx] 
Sent: Tuesday, August 09, 2011 4:55 PM
To: David Green
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  Struggling with MySQL query

On Tue, Aug 9, 2011 at 10:14 AM, David Green <simpill@xxxxxxxxx> 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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux