Omar Alhadidy Omar Alhadidy - 3 months ago 7
MySQL Question

Arrange data in MySQL tables

I have a users table and a categories table which already contain data,
I also have a third table which called

user_category
which has three
columns(id,user_id,category_id)
.

When the user first register he must choose a category or more than one from a dropdown. I want to insert the id of the user to
user_id
columns and the id of each category to the
category_id
so if the user choose more than one category he will have more than one record in the
user_category
table.

Answer

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