检索表的最后插入ID以在另一个表中用作外键

I have table(table1 and table2) that ID of table1 are foreign key of table2. in INSERT I want to save last ID inserted in table1 for insert to foreign key of table2. In your idea what is best way for it?

Use Like this in Your Code:

$result= mysql_query("Your SelectQuery");   
$lastId  = mysql_insert_id();

And Use $lastId variable . And You Can Get Your REsult.

You Can Also Use JOINs For join 2 tables And use last_insert_id for table 1.

Use LAST_INSERT_ID() function, to get the last inserted auto incremented column's value.