MySQL Forums
Forum List  »  PHP

How to insert record to a table and simultaneously update the bridge table?
Posted by: Rich Wood
Date: January 17, 2014 03:37PM

Hello all. I have researched a ton before submitting and appreciate your help. I believe I am just missing the concept of bridge tables and the answer is most likely very simple.

I have two tables
- tblRegistrants
- tblEvents

To help further understand the following here is the table with the key columns of each

tblRegistrants
- *regID (auto increment PK)
- firstName

tblEvents
- eventID (auto increment PK)
- eventName
- eventOwnerID (this receives the *regID of the person submitting the form)


A user logs in at which point I capture their *regID from the tblRegistrants table.
The user submits a new event via an event form.
The event form submits all of it's field data to one table tblEvents.
In tblEvents is a column called eventOwnerID. With the ID of the logged in user, I simply write that value to that column.

This all works perfectly.

In order for me to associate the registrant (tblRegistrant) with the various events that they submitted (tblEvents), I built a bridge table called tblEventOwners.

tblEventOwners
- regID
- eventID


In tblEventOwners I have the columns regID and eventID, whereby in the above scenario it would show the value of the person logged in's ID for regID and the event that was JUST CREATED auto incremented eventID.

What is the standard procedure for utilizing this bridge table?

Do I write to this table after the event is submitted, retrieve the events ID, and then execute another insert for the bridge?

OR

Do I set up a stored procedure or action of some type on the DB side so this occurs automatically?

This is the key concept I am missing and can not seem to find the answer anywhere.

I am also not exactly sure if I HAVE to define the columns within tblEventOwners as foreign keys or not.

Thanks for your help!
Rich

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.