help mysql update - 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 mysql update (
/showthread.php?tid=294021)
help mysql update -
TheBluec0de - 30.10.2011
how to save on mysql, deaths ?? give me an example ?
Re: help mysql update -
Pinguinn - 30.10.2011
Somewhere at the top
pawn Код:
#define TABLE_NAME "[table name here]"
new pDeath[MAX_PLAYERS];
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
if(killerid != INVALID_PLAYER_ID)
{
pDeath[playerid]++;
}
}
public OnPlayerDisconnect(playerid)
{
// make sure you have already connected to the database
new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name));
mysql_query("UPDATE %s SET death = '%d' WHERE name = '%s'", TABLE_NAME, pDeath[playerid], name);
}
Re: help mysql update -
TheBluec0de - 31.10.2011
ok, another question for the kills?
Re: help mysql update -
[NoV]LaZ - 31.10.2011
Quote:
Originally Posted by Pinguinn
Somewhere at the top
pawn Код:
#define TABLE_NAME "[table name here]" new pDeath[MAX_PLAYERS];
pawn Код:
public OnPlayerDeath(playerid, killerid, reason) { if(killerid != INVALID_PLAYER_ID) { pDeath[playerid]++; } }
public OnPlayerDisconnect(playerid) { // make sure you have already connected to the database new name[MAX_PLAYER_NAME]; GetPlayerName(playerid, name, sizeof(name)); mysql_query("UPDATE %s SET death = '%d' WHERE name = '%s'", TABLE_NAME, pDeath[playerid], name); }
|
You would need to format the query before sending it, since mysql_query doesn't.
pawn Код:
new query[256];
format(query, sizeof (query), "UPDATE `users` SET `death` = %d WHERE `name` = '%s'", pDeath[playerid], name);
mysql_query(query);
or, if you're using BlueG's plugin you can use mysql_format.
pawn Код:
new query[256];
mysql_format(-1, query, "UPDATE `users` SET `death` = %d WHERE `name` = '%s'", pDeath[playerid], name);
mysql_query(query);
And for the kills, you do exactly the same thing, only that you're updating the kills column instead of the death one.
Re: help mysql update -
TheBluec0de - 31.10.2011
and add to the table, kills and deaths, I put them with: kills - INT - 11, deaths - INT - 11, or 20 ?
Re: help mysql update -
TheBluec0de - 31.10.2011
so ?
Respuesta: help mysql update -
GantaIgarashi - 31.10.2011
Add them.
Re: help mysql update -
TheBluec0de - 31.10.2011
kills - INT - 11, deaths - INT - 11 ?
Re: help mysql update -
TheBluec0de - 31.10.2011
so ?
Re: help mysql update -
TheBluec0de - 31.10.2011
bump