[PHP-DB] SQL Join problem (Firebird)

2003-09-03 Thread Evan Morris
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 - SOMEVALUEbr;
};

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.SOMEVALUEbr;

This has unexpected results (it echoes the literal text SOMEVALUE).

So, what's the answer? Simply rename one of the SOMEVALUE fields in the
database? Or is there a way to differentiate them at the PHP level?

I know one can alias them in the SQL statement itself, like SELECT
t1.SOMEVALUE, t1.SOMEOTHERVALUE, t2.SOMEVALUE, t2.SOMEOTHERVALUE from TABLE1
t1 JOIN TABLE2 t2 ON t1.SOMEOTHERVALUE = t2.SOMEOTHERVALUE

However, you cannot go

echo $row-t1.SOMEVALUEbr

since this again echoes the literal text SOMEVALUE (ie, the field name).

Any and all help appreciated.

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



Re: [PHP-DB] SQL Join problem (Firebird)

2003-09-03 Thread Sean Burlington
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 - SOMEVALUEbr;
};
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.SOMEVALUEbr;

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

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