|
I want to link a number of tables together.
For example. I have a person table. Each person has a number of addresses (Home, Business, etc), E-mail addresses, telephone numbers, etc. So tbl_person has a unique key Person_ID (auto increment). Up to now I have been re-reading the tbl_person to get this key to write to tbl_address (unique key is Address_ID), etc.
I have now found that I can use $PersonID=mysql_insert_id() to get the id of the last insert row.
Will this still work (i.e., return the id I just added) if there are 5,000 people on at the same time updating the tbl_person or will it return the last id added by the last person adding to the table?
Next I want one tble_address for person addresses and supplier addresses, etc.
As I have no control of the key generated (i.e., tbl_person will have a key of 1 and tbl_supplier will have a key of 1 (not related). Therefore, I would need to write to Person_ID on tbl_address when adding a person relationship and Supplier_ID on tbl_address when adding a supplier relationship. I would therefore need a field for each relationship.
Another way is to set up a table of keys tbl_key_person_address (Tbl_ID, Person_ID and Address_ID), tbl_supplier_address (Tbl_ID, Supplier_ID and Address_ID). This way I would need to have a table for each new relationship. However, I would not need to add a new field to each table(i.e., tbl_address, tbl_telephone_number, etc) when ever I required a new relationship (e.g., tbl_contacts).
Am I on the right track or is there a far better way of doing this?
Regards,
Glyn
|