MySQL check for duplicate records
#2

You should set a composite UNIQUE key, e.g. userid + itemid. That's was that function was designed for. Then you can use the construct:
PHP код:
INSERT ... ON DUPLICATE KEY UPDATE ... 
Let's say that there is a row with userid = 1 and itemid = 1
Inserting the following will work:
userid 1 and itemid 2
userid 2 and itemid 1
But if you try to insert userid 1 and itemid 1 again, it will fail and use the update clause instead, e.g.
PHP код:
INSERT INTO inventory (useriditemidamountVALUES (1,1,42ON DUPLICATE KEY UPDATE amount amount 42 
Affected rows will then return: 1 if the row was inserted or 2 if an existing row was updated.

See also here: https://sampforum.blast.hk/showthread.php?tid=505081. Section 'Setting limits'.
Reply


Messages In This Thread
MySQL check for duplicate records - by dusk - 15.05.2014, 12:46
Re: MySQL check for duplicate records - by Vince - 15.05.2014, 12:59
Re: MySQL check for duplicate records - by dusk - 15.05.2014, 13:06

Forum Jump:


Users browsing this thread: 1 Guest(s)