php - Storing values in two MySQL tables -


i have scenario in not sure do.

i have website user can update status. allowing use of hash tags possible user post might like:

went great hike today!! #hiking

now, intend store post in table appropriately named "posts" structured this:

post_id | user_id | text | date 

now, when user submits form holds post text run script create array of hash tag terms user used , store them in array. can loop through array , insert tags aptly named "tags" table. structure of table this:

tag_id | post_id | user_id | tag 

the problem not know post_id of post until after insert data "posts" table (post_id primary key , auto increment). now, thinking select last row of data "posts" table user (after insert post), , in turn use returned post_id query inserts tag data "tags" table. seems not best way? question is:

is best solution or there better way go scenario?

i brand new stack overflow, don't please down vote me. comment , tell me doing wrong , learn , ask better questions.

thanks

have new column in both tables - unique_id - holds string generate in code before querying database. way have id tie posts , tags before submission. use method time similar applications.

only issue uniqueness, there variety of ways generate unique ids (i use mixture of timestamps , hashing).


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -