Help with UPDATE mysql - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with UPDATE mysql (
/showthread.php?tid=659838)
Help with UPDATE mysql -
DarkWorldJack - 18.10.2018
hello, I would have a problem, I would like to understand why when I save the ammo with the weapon that is already present in MYSQL, instead of modifying the number of ammunition I create another string with the weapon + the additional ammunition.
Код:
mysql_format(mysql, query, sizeof(query), "INSERT INTO weapon_house VALUES (%d, %d, %d) ON DUPLICATE KEY UPDATE `Ammo` = `Ammo`+'%d'", PlayerInfo[playerid][ID], weapon, inputtext[0], inputtext[0]);
mysql_tquery(mysql, query);
Thanks to those who lose time for me <3
Re: Help with UPDATE mysql -
khRamin78 - 18.10.2018
if i read it right i think your problem is with your keys and sql table anyway just in case :
your player sql id and weapon id needs to be unique in case of using this style
Код:
Ref Mysql Learning pdg >>>
If you specify an ON DUPLICATE KEY UPDATE clause and a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY, an UPDATE of the old row occurs. For example, if column a is declared as UNIQUE and contains the value 1, the following two statements have similar effect:
INSERT INTO t1 (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=c+1;
UPDATE t1 SET c=c+1 WHERE a=1;
Код:
/*
(The effects are not identical for an InnoDB table where a is an auto-increment column. With an auto-increment column, an INSERT statement increases the auto-increment value but UPDATE does not.)
*/
Код HTML:
UNIQUE KEY `weaponid`
so just try checking the weaponid too if its uniqe or prm so if its not make it then and if it is and player sqlid is too then try to
insert and update in different functions
Re: Help with UPDATE mysql -
DarkWorldJack - 18.10.2018
sorry, can you explain to me with the string I used that I did not understand so much?
Re: Help with UPDATE mysql -
khRamin78 - 18.10.2018
Quote:
Originally Posted by DarkWorldJack
sorry, can you explain to me with the string I used that I did not understand so much?
|
not with your code your table you have to set player id weapon id to be unique
Re: Help with UPDATE mysql -
DarkWorldJack - 18.10.2018
thanks, Resolved <3
Re: Help with UPDATE mysql -
khRamin78 - 18.10.2018
Quote:
Originally Posted by DarkWorldJack
thanks, Resolved <3
|
your welcome