Re: MySQL Alias and PHP
| From: | Charles Kline | Date: | Fri, 07 Mar 2003 23:48:27 +0000 |
| Subject: | Re: MySQL Alias and PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138705@lists.php.net to get a copy of this message | ||
Wow. That is ALMOST it. The only thing is it does not return the record with a 0 in tbl_1.area_2 - can you think of a workaround?
Thanks for the help,
Charles
On Friday, March 7, 2003, at 06:39 PM, Barajas, Arturo wrote:
Let's see: SELECT tbl_1.area_1, areas1.area_name, tbl_1.area_2, areas2.area_name FROM tbl_1 INNER JOIN tbl_2 areas1 ON tbl_1.area_1 = areas1.id INNER JOIN tbl_2 areas2 ON tbl_1.area_2 = areas2.id Maybe if you tinker a little on the sentence. I don't have a place to test it right now. -- Un gran saludo/Big regards... Arturo Barajas, IT/Systems PPG MX (SJDR) (427) 271-9918, x448-----Original Message----- From: Charles Kline [mailto:ckline@rightcode.net] Sent: Viernes, 07 de Marzo de 2003 04:09 p.m. To: Jim Lucas Cc: php-general@lists.php.net Subject: Re: [PHP] MySQL Alias and PHP 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-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpid area_1 area_2 1 2 3 2 1 2 3 5 0tbl_2id area_name 1 funding 2 research 3 new 4 ongoing 5 otherSo, 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 sameinfo. On Friday, March 7, 2003, at 11:09 AM, Rich Gray wrote:How do I echoHi 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.area_b FROMthe values for a.id and b.id? Thnks CharlesI presume you mean area_name... Try this -> SELECT a.area_name as area_a, b.area_name as-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phptbl_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