Greetings:
I have a very large query that pulls using some joins from 3 or 4 tables. The output is then grabbed through mysql_fetch_assoc(). When I'm pulling my data in the query, I'm using table aliases like l.id, l.bedrooms, l.street FROM listings AS l
By using this, I figured I could output the data as $data['l.street'] but it doesn't work. $data['street'] works just fine.
My question is, if I have two tables with the same field name, how do I distinguish them in the output?
mysql_fetch_assoc() question regarding field names
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: mysql_fetch_assoc() question regarding field names
You'll either have to use mysql_fetch_array() and use the numeric index or alias the column name:
-or-
-or-
etc...
Code: Select all
SELECT l.id `l.id`, l.bedrooms `l.bedrooms`, l.street `l.street` FROM listings AS lCode: Select all
SELECT `l`.`id` `l.id`, `l`.`bedrooms` `l.bedrooms`, `l`.`street` `l.street` FROM listings AS `l`Code: Select all
SELECT l.id AS `l.id`, l.bedrooms AS `l.bedrooms`, l.street AS `l.street` FROM listings AS l
Last edited by AbraCadaver on Fri Mar 12, 2010 1:16 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: mysql_fetch_assoc() question regarding field names
I'd say to use aliases. If you use indexes, if the query is ever modified you might have to make a number of other changes.