instead of:

$esc_subject = $row["SUBJECT1"];

use:

$esc_subject1 = $row["SUBJECT1"];
$esc_subject2 = $row["SUBJECT2"];

and have some logic, in php, later to determine which one(s) to display

-----Original Message-----
From: phplist [mailto:[EMAIL PROTECTED]]
Sent: Friday, March 15, 2002 2:55 PM
To: 'Martin Towell'; [EMAIL PROTECTED]
Subject: RE: [PHP] Fetching 1 array from either one of 2 possible
columns?


I apologize if I wasn't clear in my email. The query part is fine I
think, as I tested it through the myPHPAdmin and had no problem with the
results (but brackets are good though).

It's this part I'm not too sure about. AS you can see, it's just using
["SUBJECT1"] as shown. Correct me if I'm wrong, but even though I have 2
results, the final output would only show 1 because it's only showing
the match in SUBJECT1?

> 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"];


> -----Original Message-----
> From: Martin Towell [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, March 14, 2002 7:42 PM
> To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
> Subject: RE: [PHP] Fetching 1 array from either one of 2 
> possible columns?
> 
> 
> use brackets
> 
> where (sub1 or sub2) and geo
> 
> -----Original Message-----
> From: phplist [mailto:[EMAIL PROTECTED]]
> Sent: Friday, March 15, 2002 2:41 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Fetching 1 array from either one of 2 possible columns?
> 
> 
> 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
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to