Possible Duplicate:
How to fetch result from MySQL row with multiple same-name columns with PHP?
I have two tables, and they share similar column names.
Query is:
SELECT a.name,b.name
FROM tablea a
JOIN tableb b ON a.id = b.id
Results are put into an array:
while ($row = mysql_fetch_array($results)){
$aname = $row['name'];
}
Once I added in that second table I noticed the $aname was using tableb’s data.
Question(s): How can I store both name columns, $row['a.name'] does not work. My guess is maybe I need to alias each result in the query. Any suggestions? Should I same avoid giving the column names in the future?
I know mysql_* is deprecated. Save your energy.
Your guess was right. You need to create an
ALIASfor the columns so you can fetch it uniquely,then you can now call