嘿所以我尝试一个upvote系统这是我的查询
bmp_image
所以它说:如果没有重复,则插入,如果行的实际UPV_VOTE等于更新的那个,则将值重新设置为0
例如:
$SQL = "INSERT INTO iDump_Upvote (UPV_Username, UPV_SujetId, UPV_Vote)
VALUES (:UPV_Username, :UPV_SujetId, :UPV_Vote)
ON UPV_VOTE = :UPV_Vote UPDATE UPV_VOTE = 0
ON DUPLICATE KEY UPDATE UPV_Vote = :UPV_Vote";
查询工作正常白线(但没有0重置)
I click on the Upvote => insert => me - 123456 - 1
I click on downvote button => update => me - 123456 - -1
i click on the downvote button again => update => me - 123456 - 0
但是创建另一个基本上会执行
的查询并不是很干净ON UPV_VOTE = :UPV_Vote UPDATE UPV_VOTE = 0
编辑
这有效:
UPDATE iDump_Upvote (UPV_Vote) VALUES(0) WHERE UPV_Username = :UPV_Username AND UPV_SujetId = :UPV_SujetId AND UPV_Vote = :UPV_Vote
感谢turo