Re: SQL Join problem (Firebird)
| From: | Sean Burlington | Date: | Wed, 03 Sep 2003 07:51:23 +0000 |
| Subject: | Re: SQL Join problem (Firebird) | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-30291@lists.php.net to get a copy of this message | ||
Evan Morris wrote:
Hi all
Say you have two tables, TABLE1 and TABLE2. Each table contains (amongst
others) a field called SOMEVALUE
Now, in TABLE1 SOMEVALUE contains "string1", but in TABLE2 SOMEVALUE
contains "string2".
Now you join these tables (on SOMEOTHERVALUE) and you loop through the
results set:
while ($row = ibase_fetch_object($sth)) {
echo "$row -> SOMEVALUE<br>";
};
This only echoes the value of SOMEVALUE last referred to in your SQL
statement (obviously, because it has no way of differentiating between the
two versions of SOMEVALUE).
However, it does not work to do
echo "$row->TABLE1.SOMEVALUE<br>";
This has unexpected results (it echoes the literal text SOMEVALUE).
alias the columns to a different name using the keyword 'as' SELECT t1.SOMEVALUE as somevalue1, t1.SOMEOTHERVALUE, t2.SOMEVALUE as somevalue2, t2.SOMEOTHERVALUE from TABLE1 t1 JOIN TABLE2 t2 ON t1.SOMEOTHERVALUE = t2.SOMEOTHERVALUE echo $row->somevalue1 echo $row->somevalue2 -- Sean