Which will cause the ON DUPLICATE KEY UPDATE statement to increase the value by 2 instead of 1, SQL im is used here:
INSERT INTO banner_view (banner_id,date,views)
VALUES ('10',CURDATE(),'1')
ON DUPLICATE KEY UPDATE views=(views+1)
Here is the database schema:
CREATE TABLE `banner_view` (
`banner_id` int(11) UNSIGNED NOT NULL ,
`date` date NOT NULL ,
`views` int(10) UNSIGNED NOT NULL ,
PRIMARY KEY (`banner_id`, `date`),
FOREIGN KEY (`banner_id`) REFERENCES `banner` (`banner_id`) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE INDEX `banner_id` USING BTREE (`banner_id`, `date`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
ROW_FORMAT=COMPACT
;
I checked the MySQL log to ensure that the query is called exactly 3 times, but the output will be 6, what could be wrong?
UPDATE: this method is called inside the smarty template, for example: {App_banner :: getRandomBanner ()}
source
share