Re: MySQL Alias and PHP

From: Date: Fri, 07 Mar 2003 22:08:34 +0000
Subject: Re: MySQL Alias and PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-138700@lists.php.net to get a copy of this message
Thanks for all the suggestions, I have tried all and more and still can't get this quite right. If there is a better forum for these question, please point me to it and I will take this somewhat off topic thread elsewhere. My table structure is like so: tbl_1
id        area_1        area_2
1          2                   3
2          1                   2
3          5                   0
tbl_2
id         area_name
1          funding
2          research
3          new
4          ongoing
5          other
So, I need to display all the records in tbl_1 and show the values for the fields area_1 and area_2 as their area_name field from tbl_2. I must display each record from tbl_1 only once. I know I am close, but I just can't get this to work. The closest I have gotten is this: SELECT DISTINCT a.area_name area_a, b.area_name area_b FROM tbl_1 x, tbl_2 a, tbl_2 b WHERE x.area_1 = a.id OR x.area_2 = b.id GROUP BY x.id But this ALWAYS returns the area_name (funding) in the value of area_b (have no idea why) Thanks for any help. It is appreciated. - Charles On Friday, March 7, 2003, at 01:42 PM, Jim Lucas wrote:
Then the information in the DB is the same. Jim ----- Original Message ----- From: "Charles Kline" <ckline@rightcode.net> To: "Rich Gray" <rich@f1central.net> Cc: <php-general@lists.php.net> Sent: Friday, March 07, 2003 10:03 AM Subject: Re: [PHP] MySQL Alias and PHP Thanks for the help. Almost there. Here is what I have: SELECT x.id, x.headline, x.description, a.area area_a, b.area area_b FROM tbl_funding x, tbl_dra a, tbl_dra b GROUP BY x.id LIMIT 0 , 30 The problem is that $array[area_a] and $array[area_b] display the same info. On Friday, March 7, 2003, at 11:09 AM, Rich Gray wrote:
Hi all, I have this query: SELECT a.area_name, b.area_name FROM tbl_1 x, tbl_2 a, tbl_2 b WHERE x.area_1 = a.id AND x.area_2 = b.id I am using PEAR DB to get my results as an ASSOC ARRAY. How do I echo the values for a.id and b.id? Thnks Charles
I presume you mean area_name... Try this -> SELECT a.area_name as area_a, b.area_name as area_b FROM tbl_1 x, tbl_2 a, tbl_2 b Then you can refer to the columns as $array['area_a'] and $array['area_b'] HTH Rich
-- 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


« previous php.general (#138700) next »