rvdb86 Posted October 6, 2009 Share Posted October 6, 2009 Hi, I have the following tables: apartments apartmentID apartmentName apartmentType apartmentTypeID apartmentTypeName appliances applianceID applianceName link_apartmentType id typeID apartmentID link_appliances id applianceID apartmentID the tables with the link_ prefix connect the apartments to their type and appliances. The apartments can only have 1 type but many appliances. How would I print a list of all apartments, with their type and their appliances? Thank you in advance for any help! Quote Link to comment https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/ Share on other sites More sharing options...
nafetski Posted October 6, 2009 Share Posted October 6, 2009 Looks like a join from apartments.apartmentID to link_appliances.apartmentID AND link_apartmentType.apartmentID group by apartments.apartmentID? Quote Link to comment https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/#findComment-931950 Share on other sites More sharing options...
rvdb86 Posted October 6, 2009 Author Share Posted October 6, 2009 sounds about right, any chance you can post the code, thats the part i'm stuck on. i think it has to be something like: $result = mysql_query('SELECT * INNER JOIN link_type ON apartments.apID = link_type.apID INNER JOIN apartmentType ON link_type.typeID) or die(mysql_error()); I am bit of a newbie when it comes to connecting tables in php mysql. I appreciate the help Quote Link to comment https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/#findComment-931958 Share on other sites More sharing options...
rvdb86 Posted October 7, 2009 Author Share Posted October 7, 2009 I still have not managed to solve the problem heres the pseudo code of what should happen: [*]Get all apartments from the database [*]For each apartment get apartment type ID from link_type table [*]Get type name from apartmentTypes table through use of typeID [*]Get all appliances from link_appliances through use of apartmentID [*]For each appliance get appliance name through use of applianceID from table appliances [*]Print apartment name [*]Print apartment type [*]For each appliance print appliance name I hope this explains my problem and maybe some one can help me out Quote Link to comment https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/#findComment-932423 Share on other sites More sharing options...
Zane Posted October 7, 2009 Share Posted October 7, 2009 Hi, I have the following tables: apartments apartmentID apartmentName apartmentType apartmentTypeID apartmentTypeName appliances applianceID applianceName link_apartmentType id typeID apartmentID link_appliances id applianceID apartmentID You have you DB structure all wrong.. If your apartments can only have on type then you should put that as an attribute (another field) in the apartments table. Not link them in another table. If you have multiple appliances in multiple apartments, then link each appliance to its apartment. i.e put the apartment as an attribute to the appliance. So now.. it should look something like apartments apartmentID apartmentName apartmentTypeID apartmentType apartmentTypeID apartmentTypeName appliances applianceID applianceName apartmentID Next part is linking them together .... which I'm no good at. Quote Link to comment https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/#findComment-932437 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.