Im gonna try to explain what I need to do.
I have a table and in that table I have ID. This ID is my primary key (auto_increment).
And I have a second table.
What I need is when I save something in my seconds table I want to use the ID of my first table.
I have read much things but I only got more headache from it so if anyone could help me with this I would be gratefull.
Rgrds
You need the concept of a foreign key. This can be defined as a constraint or just used as such. Let’s assume you have “Teachers” and “Pupils” and pupils are assigned to one teacher. So the teacher has an
ID. Now your “Pupils” table has an ID as well (it’s primary key) and a foreign keyTEACHER_ID, which refers to the teacher entry.will create a constraint, that
TEACHER_IDrefers to theIDof a Teacher.In PHP if you create both entries at once. You can first insert the teacher and then use:
which will return you the last
auto_incrementvalue (in this case your teachersID) and then set this as theTEACHER_IDfor your pupils entry.