deansaddigh Posted June 21, 2009 Share Posted June 21, 2009 Hi, I have a problem and am trying to figure out the best way to solve it... I have three tables post user_post user When a user creates a post I want to store this in the post and user post table. They have to be logged in to do so. The problem i have is inserting data into the user_post table I have a problem. In order to write to the user_post table I need to have the userid and the postid. Getting the userid is not a problem as i already have this detail stored in the session. To get the post id ready to insert into the user_post table I have no 'full proof' way of doing so. As there is nothing unique in the post table apart from the post id which i am trying to access I have no way of querying it to get this result. The only options that i can think of are: select the max postid and take that assuming that this must be the one that the user has entered OR select the postid based on the post text and datetime stamp. However if multiple users post at similar time with the same message etc this would become a problem# Any suggestions would be much appreciated Thanks Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted June 21, 2009 Share Posted June 21, 2009 insert into your post table then use last_insert_id(); http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 21, 2009 Share Posted June 21, 2009 should of posted in the MySQL Help section you would of got much more help.. with this kind. Quote Link to comment Share on other sites More sharing options...
deansaddigh Posted June 21, 2009 Author Share Posted June 21, 2009 Sorry about posting in the wrong, section ill make sure i post in the right section nxt time. thanks for the reply thats exactly what i needed. thanks again Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.