Welcome Guest, Not a member yet? Register   Sign In
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.




Theme © iAndrew 2016 - Forum software by © MyBB