Answer the question
In order to leave comments, you need to log in
How to work with linked tables through php?
There are two related tables by key and secondary value.
The question is how to populate such tables via php?
What will the query look like in the database if, for example, when filling in the Reviews table, what will happen to the id_categoryRev field?
And what is the most logical thing to do in a situation where some category is deleted, what to do with a review from this category?
And how will all this be affected by cascading updates and deletions?
Thanks in advance to anyone who can help clarify the situation! :)
array('Category' =>
'id_category INT(30) PRIMARY KEY NOT NULL AUTO_INCREMENT, '
, 'id_signin INT(30) NOT NULL, '
, 'nameCategory VARCHAR(50) NOT NULL'
)
, array('Reviews' =>
'id_review INT(30) PRIMARY KEY NOT NULL AUTO_INCREMENT, '
, 'id_categoryRev INT(30) NOT NULL, '
, 'fio VARCHAR(50) NOT NULL, '
, 'email VARCHAR(50) NOT NULL, '
, 'review TEXT(5000) NOT NULL'
, 'FOREIGN KEY (id_categoryRev) REFERENCES Category (id_category) ON DELETE CASCADE ON UPDATE CASCADE'
Answer the question
In order to leave comments, you need to log in
According to the 'ON DELETE CASCADE ON UPDATE CASCADE' entry, when a category is deleted, all reviews related to it will also be deleted. When you change the `id_category` of a category, the `id_categoryRev` field of the corresponding reviews will also be changed.
Since the `id_categoryRev` field is NOT NULL, you must define a category when writing a review to the database, otherwise MySQL will generate an error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question