There is a table to which views are added. So if there is an entry in the table with these users, you should NOT add an entry but change the existing one. Sample trigger code:
CREATE TRIGGER before_insert_view BEFORE INSERT ON ad_views FOR EACH ROW BEGIN SET @idExists = (SELECT ad.id FROM ad_views av WHERE av.ip_address = NEW.ip_address AND av.ad_id = NEW.ad_id); IF @idExists THEN UPDATE ad_views av SET av.quantity = av.quantity + 1; //ΠΡΠΌΠ΅Π½ΠΈΡΡ Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ΅ΠΉ Π·Π°ΠΏΠΈΡΠΈ; ELSE //ΠΡΠ΅ Π½ΠΎΡΠΌΠ°Π»ΡΠ½ΠΎ, ΠΌΠΎΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ ΡΠ΅ΠΊΡΡΠΈΠΉ Π·Π°ΠΏΠΈΡΡ; END IF; END;
RETURN NULL;- when not to write. - aleks.andrRETURN NULL. From the trigger, call it. - aleks.andrON DUPLICATE KEY UPDATEconstruct? - Venta