Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/176757-get-all-values-from-linked-tables/
Share on other sites

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

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.