I'm working on a form that queries by selection in PHP, where a user
selects a subject and an optional selection of geographic region to get
information. Each database entry will have 2 subject fields, Subject 1
being the main subject and Subject 2 being the cross-subject, and a
geographic field, which is optional. A table is set up like this:

+------+--------------+------+----------+----------+-------------+
| ID   | Organization | URL  | SUBJECT1 | SUBJECT2 | Geographic  |
+------+--------------+------+----------+----------+-------------+
|  1   | Acme         | www  |  Math    |  English | Canada      |
|  2   | Loony Toons  | www  |  Comedy  |  Math    | Brazil      |

...


The idea is that the query will check the database to see if $Subject
has a match in either Subject1 or Subject2. The geographic is an
optional selection. If I select a country, then that's fairly simple.
However, if I select Math as a subject, and left the Geographic option
unselected, I want it to select all records that has a match in either
Subject1 and Subject2, irregardless of the Geographic option.

I tried the following query:

SELECT * FROM links WHERE (SUBJECT1='Legislation' OR
SUBJECT2='Legislation') AND GEOGRAPHIC = ''

But it won't find the above records because the geographic is not a
blank field.

I could drop the ".. AND GEOGRAPHIC" part, but then if someone does
select a country, it won't take country into consideration. How do I get
it to select all records based on the subject, irregardless of the
country?

Thanks in advance,

Lmlweb



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to