Skip to content
Advertisement

How I pass the id from one table in a row in another table?

I am generating some football fixtures and what I try to do is to insert the fixtures and the games in two tables. The fixtures table is good to go but I am struggling with inserting matches in the ‘match’ table because this table have a foreign key to ‘fixture’ table.

fixture table

match table

php algorithm

How can I pass the fixture.id_fixture to the match.fixture as the games are generated?

Advertisement

Answer

You can use $link->insert_id.

I removed the ID columns from your queries, because I assumed that all of them were auto-generate ID, in which case you do not need to pass NULL for each one of them.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement