grungefreak Posted April 4, 2008 Share Posted April 4, 2008 I have a small discussion forum. There is a "threads" table in the db and a "topics" table in the db. When a user creates a thread, it is inserted into the "threads" table from the php script. But I want the primary key of that record to be inserted as a foreign key into the "Topics" table. I know this can be done through php but someone suggested that I can set the field in the database to automatically grab the pk of the last thread. Any ideas on how this would be done? GF Link to comment https://forums.phpfreaks.com/topic/99597-php-and-mysql-query/ Share on other sites More sharing options...
craygo Posted April 4, 2008 Share Posted April 4, 2008 mysql_insert_id() http://us.php.net/manual/en/function.mysql-insert-id.php This will grab the insert id from the last insert Ray Link to comment https://forums.phpfreaks.com/topic/99597-php-and-mysql-query/#findComment-509530 Share on other sites More sharing options...
grungefreak Posted April 4, 2008 Author Share Posted April 4, 2008 mysql_insert_id() http://us.php.net/manual/en/function.mysql-insert-id.php This will grab the insert id from the last insert Ray Thanks Ray, I know about that PHP function, I am wondering can this be done through the database itself? GF Link to comment https://forums.phpfreaks.com/topic/99597-php-and-mysql-query/#findComment-509557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.