scarezekiel Posted June 11, 2012 Share Posted June 11, 2012 I have these two tables. One of it is (tbllocation) and the other (tbldistrict). So i need to display the datas but the problem is both of the column names that i wanna display have same column names which is (description).i dont know how to do it.if i use both (description), it will only show the data from (tbllocation). so here are my codes <table style="text-align: left; width: 715px; height: 32px;" border="1" cellpadding="2" cellspacing="2"> <tbody> <tr> <td colspan="2" rowspan="1" style="font-style: italic;">List-Location</td> </tr> <tr> <td style="font-style: italic;">code</td> <td style="font-style: italic;">description</td> <td style="font-style: italic;">districtid</td> </tr> <? $query="SELECT * FROM tbllocation LEFT JOIN tbldistrict ON tbllocation.districtid = tbldistrict.id"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { $code = $row['code']; $description = $row['description']; $districtid = $row['districtid']; echo "<tr><td>$code</td>"; echo "<td>$description</td></tr>"; echo "<td>$districtid</td></tr>"; } ?> </tbody> </table> and the photo explains from what it is now(photo 1)..and how do i want it to be..(photo 2) Quote Link to comment https://forums.phpfreaks.com/topic/263972-how-to-display-data-from-two-different-table-with-the-same-column-names/ Share on other sites More sharing options...
ignace Posted June 11, 2012 Share Posted June 11, 2012 Either alias the column or access them using their numeric indices. tbl2.description as description2 OR $row[3] Quote Link to comment https://forums.phpfreaks.com/topic/263972-how-to-display-data-from-two-different-table-with-the-same-column-names/#findComment-1352850 Share on other sites More sharing options...
scarezekiel Posted June 11, 2012 Author Share Posted June 11, 2012 i dont know how to combine the alias to the current query.can u perhaps help me alter mine. Quote Link to comment https://forums.phpfreaks.com/topic/263972-how-to-display-data-from-two-different-table-with-the-same-column-names/#findComment-1352859 Share on other sites More sharing options...
Illusion Posted June 11, 2012 Share Posted June 11, 2012 Alias example http://www.w3schools.com/sql/sql_alias.asp Quote Link to comment https://forums.phpfreaks.com/topic/263972-how-to-display-data-from-two-different-table-with-the-same-column-names/#findComment-1352878 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.