RE: [PHP] Struggling with MySQL query

From: Date: Tue, 09 Aug 2011 14:59:40 +0000
Subject: RE: [PHP] Struggling with MySQL query
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-314449@lists.php.net to get a copy of this message
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@gmail.com] Sent: Tuesday, August 09, 2011 4:55 PM To: David Green Cc: php-general@lists.php.net Subject: Re: [PHP] Struggling with MySQL query 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#314449) next »