Click to See Complete Forum and Search --> : Joining tables


Siriunson
11-23-2007, 02:46 PM
I am fairly new to databases & have the very helpful book "PHP Web Development with Dreamweaver MX 2004" published by Apress for my guide. I'm using DW8 & have built a database in phpMyAdmin that has tables for parents, their children, the child's class, year & school.

The parents table has parent_id & parentchild to link these tables. The child table has childschool, childyear & childclass fields, all of which are INT to link to the relevant tables by their _id (school_id etc).

I would like to have a page on which I can display a parent's details (parents_Details.php) and their related child plus the child's details. I have no idea how to go about joining all these tables in a recordset, so I can display the schoolname, yearname & classname fields as text rather than the table's _id number.

I would be very grateful of any help.

chazzy
11-24-2007, 07:16 AM
You wouldn't. They're three completely distinct objects. You should get the first set (the parents) then find all the children for that parent. What happens if a child has 2 parents?

Siriunson
11-24-2007, 07:39 AM
Maybe the child_id & childparent could link to the parent_id & use a repeat region to display all records? If I add the field parentchild to the parent table, could I work backwards to access the child details?

Currently, my parent results page has links to each parent via the parent_id= param. On the parent details page, I have a recordset that filters childparent=URL parent_id & draws the information from the child table. So far so good...

Its adding the school, year & class info in a way that displays each tables name rather than _id that is where I'm stuck.