• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
storing record in tables, that relate to multiple id's

#1
[eluser]Brad K Morse[/eluser]
I have a form the user will enter a comment, that can relate to multiple steps, which the user may select.

Each step is assigned an id.

What I need to do is, is store the comment, in the comments table: (comments.id, comments.message) and then take the array of steps the user selected (steps.id) and insert that into the transactions table, which will consist of transactions.comment_id and transactions.step_id

So the user submitted a comment, and selected 4 steps, the id's of those steps are: 2, 5, 6, 7

the comment will be stored into the comments table, have an id auto-incremented, in this example, the comment id will be 12

So now I need to insert into the transactions table, this is what I want it insert (into transactions table) as:

comment_id: 12 | step_id: 2
comment_id: 12 | step_id: 5
comment_id: 12 | step_id: 6
comment_id: 12 | step_id: 7

I know I will have to store all the step_id's into an array, and then run a query for each value, inserting the comment_id that was generated when the comment was inserted into the comments table.

I am unsure on how to accomplish getting that id automatically after it was generated.

I am using an oracle database (oci8)

To sum it up, I need to grab the newly generated primary key from the comments table (comments.id), then store that into the transactions table (transactions.comment_id) 'x' amount of times, based on how many values are stored within the step_id array, so if the user assigned it to the step_id's 2, 5, 6, 7 then there would be 4 inserts into the transactions table, like you see above.

Any help is appreciated.


Messages In This Thread
storing record in tables, that relate to multiple id's - by El Forum - 11-29-2010, 08:32 AM
storing record in tables, that relate to multiple id's - by El Forum - 11-29-2010, 10:13 AM
storing record in tables, that relate to multiple id's - by El Forum - 11-29-2010, 10:34 AM
storing record in tables, that relate to multiple id's - by El Forum - 11-29-2010, 10:48 AM
storing record in tables, that relate to multiple id's - by El Forum - 11-29-2010, 02:20 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.