If i have this Query:
SELECT tableA.Id, tableB.Id FROM tableA JOIN tableB ON (tableA.bId = tableB.Id开发者_运维知识库)
Now if i try this in php i have some problems:
while($result = mysql_fetch_array(mysql_query(/Query Above/)){
print $result['tableB.Id'];
}
Now i know what you are going to say that i should do my query as:
SELECT tableA.Id AS aId, tableB.Id AS bId
FROM tableA
JOIN tableB ON (tableA.bId = tableB.Id)
and then use: $result['bId']
But the fact is the query is actually like this:
SELECT tableA.*, tableB.* FROM tableA JOIN tableB ON (tableA.bId = tableB.Id)
Is there any way i can get the result in PHP without doing the AS for each individual matching row?
Thanks
You can't, per the PHP manual:
"If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysql_fetch_row() or add alias names."
cf. http://www.php.net/manual/en/function.mysql-fetch-assoc.php
精彩评论