Help data won't load from 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 data won't load from MySQL (
/showthread.php?tid=542932)
Help data won't load from MySQL -
X337 - 23.10.2014
Hey all, i have some problem when load player data from database.
Please help me, i can't fix it.
There's the script.
Код:
stock LoadPlayerInfo(playerid)
{
new
Query[67],dkills, ddeaths, dmoney, dlevel, dexp, dexpL, pname[16];
mysql_real_escape_string(pName(playerid), pname);
format(Query, sizeof(Query), "SELECT `kills`,`deaths`,`money`,`Level`,`EXP`,`EXP_L` FROM `playerinfo` WHERE `user` = '%s'", pname);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(Query))
{
sscanf(Query, "p<|>iffff", dkills, ddeaths, dmoney, dlevel, dexp, dexpL);
PVar[playerid][pKills] = dkills;
PVar[playerid][pDeaths] = ddeaths;
GivePlayerMoney(playerid, dmoney);
PVar[playerid][pLevel] = dlevel;
PVar[playerid][pExp] = dexp;
PVar[playerid][pExpL] = dexpL;
}
}
format(Msg, sizeof(Msg), "DATA : %d %d %d %d %d %d", dkills, ddeaths, dmoney, dlevel, dexp, dexpL);
SendClientMessage(playerid, COLOR_CADETBLUE, Msg);
mysql_free_result();
return 1;
}
Can you help me to fix it?
Thanks
Re: Help data won't load from MySQL -
AzaMx - 23.10.2014
More info(s)?
Re: Help data won't load from MySQL -
dusk - 23.10.2014
What does the mysq log say?
Also a few tips:
You don't need to check if mysql_num_rows, the while loop will only run if there are any as mysql_fetch_field moves the internal cursor or returns 0 if there are no more rows.
Why are the size of player name variable is only 16? You should use the constant MAX_PLAYER_NAME