I have a users table and a categories table which already contain data,
I also have a third table which called
user_category
columns(id,user_id,category_id)
user_id
category_id
user_category
Use This
SELECT user_id FROM users
ORDER BY user_id DESC
LIMIT 1
This will give you the last user_id which has inserted Now by using this user id you can insert the category_id by for each loop or for loop