• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Join Question

#1
[eluser]Jbeasley6651[/eluser]
I have 3 tables

table 1 - listing
fields - id, property_type_code, property_feature_code, other stuff....

table 2 - property_feature
fields - id, code, title

table 3 - property_type
fields - id, code, title

I can join any of the 2 tables fine, but i run into a problem on how to output the results in a foreach loop when 2 of the 3 tables have the same field names

so if i were to join table 1 and table 2 i can use $row->title to show the table 2 title, but if i joined table 3 as well how would i show table 3's "title"?

#2
[eluser]Armchair Samurai[/eluser]
Use aliases:
Code:
SELECT l.*, pf.*, pt.code AS  type_code, pt.title AS type_title
FROM listing AS l
JOIN property_feature AS pf ON l.property_feature_code = pf.code
JOIN property_type AS pt ON l.property_type_code = pt.code
// continue query....
then you can call the title field from the property_type table as type_title.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.