Forums

PHP

This topic is locked

complicated query

Posted 13 Mar 2003 07:54:18
1
has voted
13 Mar 2003 07:54:18 A H posted:
Hi - It's me again.

Im using dreamweaver mx php/mysql and have this little query to run which seems not return the results as it should.

This is the query as i have it:

SELECT *
FROM members
WHERE `state` = 'colname' AND members.s_1 = 'colname1' OR members.s_2 = 'colname1' OR members.s_3 = 'colname1' OR members.s_4 = 'colname1' OR members.s_5 = 'colname1' OR members.s_6 = 'colname1' AND members.zip BETWEEN '$zip_min' AND '$zip_max'

colname 1 $HTTP_POST_VARS['state']
colname1 1 $HTTP_POST_VARS['service']

$zip = $HTTP_POST_VARS['postcode'];
$zip_max = ($zip + 2);
$zip_min = ($zip - 2);

* there is a + sign in $zip_max but it doesnt seem to show up here.

Heres the deal:

I have a form that is submitted to the page this query is on.
The variable $zip is the zip code and I need to search BETWEEN a range. (The zip code plus or minus 2)

I also need to display the correct state which is passed and placed in variable 'colname'.

The third item i need to search on is a service that could be in field s_1, s_2, s_3, s_4, s_5 or s_6.

It just seems to not want to work.

Any help would be great.

Thanks.

Replies

Replied 14 Mar 2003 04:53:27
14 Mar 2003 04:53:27 A H replied:
I've fixed it. For those that this may help, the solution was to put brackets around the different field names and OR statements:

SELECT *
FROM members
WHERE `state` = 'colname' AND (members.s_1 = 'colname1' OR members.s_2 = 'colname1' OR members.s_3 = 'colname1' OR members.s_4 = 'colname1' OR members.s_5 = 'colname1' OR members.s_6 = 'colname1') AND members.zip BETWEEN '$zip_min' AND '$zip_max'

Reply to this topic