eMonk Posted June 15, 2011 Share Posted June 15, 2011 I'm running a mysql select query and just found out both tables have a same column. This is the column both tables have which is city_id: $city_id = $row['city_id']; I tried the following but it didn't work: $city_id = $row['tablename.city_id']; How can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/239398-fetching-data-from-2-mysql-tables-with-the-same-column-name/ Share on other sites More sharing options...
chintansshah Posted June 15, 2011 Share Posted June 15, 2011 You should use alias in mysql query. Ex. Select table1.city_id as city_id1, table2.city_id as city_id2 from table1,table2 So, you will get $row['city_id1']; and $row['city_id2'] It will work Quote Link to comment https://forums.phpfreaks.com/topic/239398-fetching-data-from-2-mysql-tables-with-the-same-column-name/#findComment-1229906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.