This question has already been answered:
I need
UPDATE Marks SET mark='$mark' WHERE studentid='$students[id]' AND lessonid='$lessonid' and if there are no entries in the Marks table, then add
This question has already been answered:
I need
UPDATE Marks SET mark='$mark' WHERE studentid='$students[id]' AND lessonid='$lessonid' and if there are no entries in the Marks table, then add
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
If correctly understood:
Add key to studentid and lessonid
ALTER TABLE
table_nameADD UNIQUEunique_index(studentid,lessonid);
and then ON DUPLICATE KEY
Another option is to first select
First you need to add an index:
ALTER TABLE `Marks` ADD UNIQUE INDEX (`studentid`, `lessonid`); Then you can use ON DUPLICATE KEY UPDATE
INSERT INTO `Marks` (`studentid`, `lessonid`, `mark`) VALUE ( '$students[id]', '$lessonid', '$mark' ) ON DUPLICATE KEY UPDATE mark = '$mark'; Source: https://ru.stackoverflow.com/questions/528983/
All Articles