Re: creating a SELECT AND query

From: Date: Tue, 18 Apr 2006 12:46:22 +0000
Subject: Re: creating a SELECT AND query
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-234171@lists.php.net to get a copy of this message
On 18/04/06, Ross <ross@aztechost.com> wrote: > > $query1= "select * from $table_name WHERE sname LIKE '$search_string%' "; > > if ($area="a") { > $query1 .=" AND area='a'"; > } > else { > $query1 .="AND area='$area'"; > } Firstly, you're assigning "a" to area rather than testing whether $area is "a". You need a "==" operator, not a "=". Secondly, even if you were testing $area properly, you're doing the same thing in both halves of the if-statement. Which isn't very useful. Really, you only need the "AND area='?'" part if $area is not equal to "a": if ($area != "a") { $query1 .= " AND area='$area'"; } -robin

« previous php.general (#234171) next »