Hi,

I have a problem with my SQL statment.
what I'm trying to do is:

I have 3 columns storing postcode values in my database:

postcodefirstpart
near_postcode1
near_poscode2

I have a form for the user to search the database choosing a $event_startdate, a $postcode and a $category form fields.
my SQL satatment returns the right values.
simple enough.

however when the user enter the $postcode from the form field, I want my statment to "consider" and "find" all matching values in my 3 databse columns storing postcode:

postcodefirstpart
near_postcode1
near_poscode2

$query_rsadverts = "SELECT * FROM adverts WHERE postcodefirstpart = '".$postcode."'  OR  near_postcode1 = '".$postcode."'  OR  nearpostcode2 = '".$postcode."' AND event_startdate = '".$nd."' AND sub_category = '".$category."'";
$rsadverts = mysql_query($query_rsadverts, $to_octo) or die(mysql_error());

Of course that doens't work as all my "AND" in the where clause are ignored.

However, this is the basis of what I'm trying to do

so basically if you enter the poscode:
HA1
my query should return all rows where either

postcodefirstpart = HA1
or
near_postcode1= HA1
or
near_poscode2 = HA1

AND event_startdate = '".$nd."' AND sub_category = '".$category."'";
I hope that make sense..
Many thanks,
Vinny

    Put parentheses around the decision parts:

    $query_rsadverts = "SELECT * FROM adverts WHERE (postcodefirstpart = '".$postcode."' OR near_postcode1 = '".$postcode."' OR nearpostcode2 = '".$postcode."') AND event_startdate = '".$nd."' AND sub_category = '".$category."'";

      Write a Reply...