Hi,

Since you are using a form to query the table i assume the subject1, subject
and geographic will be variables. So, you could do something like:

 SELECT * FROM links WHERE (subject1='$sub1' OR subject2='$sub2') AND
GEOGRAPHIC like '$geo%'

 In this way, if the user enters no value for the variable $geo then the
query statement will query with (WHERE geographic like '%' ) clause which
will mean any country.. On the other hand, if the user enters  a country
name for the $geo , say Canada, then the query statement will query with
(WHERE geopgrahic like 'Canada%') clause which will hit the rows with
Canada.

Gurhan


-----Original Message-----
From: phplist [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 15, 2002 7:01 PM
To: [EMAIL PROTECTED]
Subject: Fetching an optional array from an optional column


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


---------------------------------------------------------------------
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