need help for saving player stats
#1

Hi.I start using mysql but i have problem now.Server save only
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
but my code is
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Banned='%d', Warnings='%d', Kills='%d', Deaths='%d' WHERE Name='%s'", PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET AdminDuty='%d', FactionMember='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        mysql_query(string);
Where's the problem?
Reply
#2

Each time you format a string, you delete what was in it before. Try this:
pawn Код:
new string[1000];
format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank]);
format(string, sizeof(string), "%s, Banned='%d', Warnings='%d', Kills='%d', Deaths='%d'", string, PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths];
format(string, sizeof(string), "%s, AdminDuty='%d', FactionMember='%d', FactionRank='%d'", string, PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank]);
format(string, sizeof(string), "%s, Level='%d', Exp='%d' WHERE Name='%s'", string, PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][Name]);
mysql_query(string);
It should work perfectly!
P.S: you were saving Faction Rank twice.
Also, don't use the methods below where the guy uses mysql_query four times, it's bad. It's very unnecessary. All you need to do is append the continuation to the string each time you reformat. See how I do it above. After that, you only need to use mysql_query once.
Reply
#3

pawn Код:
new string[1000];
format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
mysql_query(string)
format(string, sizeof(string), "UPDATE Users SET Banned='%d', Warnings='%d', Kills='%d', Deaths='%d' WHERE Name='%s'", PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][Name]);
mysql_query(string)
format(string, sizeof(string), "UPDATE Users SET AdminDuty='%d', FactionMember='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
mysql_query(string)
format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
mysql_query(string);
Reply
#4

Quote:
Originally Posted by MrTinder
Посмотреть сообщение
Hi.I start using mysql but i have problem now.Server save only
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
but my code is
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Banned='%d', Warnings='%d', Kills='%d', Deaths='%d' WHERE Name='%s'", PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET AdminDuty='%d', FactionMember='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        mysql_query(string);
Where's the problem?
lol thats a simple mistake you forgot to call mysql_query after each format

You code should be like this
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
mysql_query(string);
        format(string, sizeof(string), "UPDATE Users SET Banned='%d', Warnings='%d', Kills='%d', Deaths='%d' WHERE Name='%s'", PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][Name]);
mysql_query(string);
        format(string, sizeof(string), "UPDATE Users SET AdminDuty='%d', FactionMember='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
mysql_query(string);
        format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        mysql_query(string);
And your string needn't be 1000 , reduce it to 200 or less.You are wasting precious memory.
Reply
#5

with this code
pawn Код:
new string[1000];
        format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d', VIP='%d' WHERE Name='%s'", PlayerInfo[playerid][Password], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Banned='%d', Warnings='%d', Kills='%d', Deaths='%d' WHERE Name='%s'", PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET AdminDuty='%d', FactionMember='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][aDuty], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        mysql_query(string);
you are querying only this
pawn Код:
format(string, sizeof(string), "UPDATE Users SET Level='%d', Exp='%d', FactionRank='%d' WHERE Name='%s'", PlayerInfo[playerid][Level], PlayerInfo[playerid][Exp], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pRank], PlayerInfo[playerid][Name]);
        mysql_query(string);
Reply
#6

Thanks all for helping.It's work now

P.S: sa-mp.com forum 4ever
Reply


Forum Jump:


Users browsing this thread: 5 Guest(s)