I'm working on a query by selection type of form, where if a user
selects a subject to get information. Each database entry will have 2
subject fields, Subject 1 being the main subject and Subject 2 being the
cross-subject. 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 Math as a subject, and left the
Geographic option unselected, I want it to go into either Subject1 and
Subject2 to find Math. In this case both records would be a hit.
Below is my query setup and formatting:
*******
$sql = "SELECT * FROM links WHERE SUBJECT1='$subject' OR
SUBJECT2='$subject' AND GEOGRAPHIC='$geographic'
ORDER BY ORGANIZATION ASC";
$sql_result = mysql_query($sql);
if (!$sql_result) {
echo "Can't execute $sql " . mysql_error();
exit;
}
// organizes data in an orderly manner (ie bulleted area)
while ($row = mysql_fetch_array($sql_result)) {
$esc_organization = $row["ORGANIZATION"];
$esc_desc = $row["DESCRIPTION"];
$esc_url = $row["URL"];
$esc_subject = $row["SUBJECT1"];
$esc_geographic = $row["GEOGRAPHIC"];
$organization = stripslashes($esc_organization);
$description = stripslashes($esc_desc);
$url = stripslashes($esc_url);
$subject = stripslashes($esc_subject);
$geographic = stripslashes($esc_geographic);
$option_block .= "
<li>
<a href=\"http://$url\">$organization</a></li><br>
$description<br>
URL: <a href=\"http://$url\">$url</a></li>\n";
}
********
Now, of course, if I were to use this, it will only use the Subject1
data. How do I tell it to use the results from either Subject 1 or
Subject 2?
Thanks in advance,
Laurie M. Landry
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php