doddsey_65 Posted February 8, 2011 Share Posted February 8, 2011 when i insert a new topic into the database its id is generated by the auto incrememnt field tid. but what i do next is insert the post for that new topic in the post table which has p_pid(post id) and p_tid(the topic id it is for). so how do i generate that p_tid when the topic has just been inserted. i used to do it by inserting the topic then running a query to pull the newest topic if from the database which would mean the post belonged to that topic. but what happens when people are posting several topics at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/227041-inserting-ids/ Share on other sites More sharing options...
micmania1 Posted February 8, 2011 Share Posted February 8, 2011 http://php.net/manual/en/function.mysql-insert-id.php Assuming your using mysql, that function will grab the last automatically generated id in your database. Quote Link to comment https://forums.phpfreaks.com/topic/227041-inserting-ids/#findComment-1171373 Share on other sites More sharing options...
doddsey_65 Posted February 8, 2011 Author Share Posted February 8, 2011 thanks for the reply. im using PDO but found the function PDO::lastInsertId() to work Quote Link to comment https://forums.phpfreaks.com/topic/227041-inserting-ids/#findComment-1171375 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.