[SOLVED] Another problem with mysql - Load info -
scuess - 11.08.2011
Hello, I've got another problem...
Now I can't load any number values from DB like Age and WantedLevel... Texts working fine.
Код:
enum _PSTATS
{
pLayaName[24],
pRealName[24],
pFavAdmin[24],
pStatus[24],
pAge,
pWantedLevel,
pViews,
pInt // Add more info
}
Код:
stock LoadPlayerInfo(iPlayer)
{
new
Query[700];
if(mysql_fetch_row(Query))
{
sscanf(Query, "e<p<|>s[24]s[24]s[24]s[24]ddd>", PVar[iPlayer]);
mysql_free_result();
}
return 1;
}
DB Setting
Код:
Age - INT(11)
WantLevel - INT(11)
Do u know where is the problem ? ^^
Re: Another problem with mysql - Load info -
JaTochNietDan - 11.08.2011
Where's the part where you're formatting and executing the query?
Re: Another problem with mysql - Load info -
scuess - 11.08.2011
Do you mean this?
Код:
stock SavePInfo(playerid)
{
if(APlayerData[playerid][LoggedIn] == true)
{
new Query[600],
yreu[600];
format(yreu, sizeof(yreu), "DELETE FROM playerinfo WHERE Nick = '%s'", pName(playerid));
mysql_query(yreu);
mysql_free_result();
format(Query, sizeof(Query), "INSERT INTO `playerinfo` (Nick, Name, FavAdmin, Status, Age, WantLevel, Views) values ('%s', '%s', '%s', '%s', '%d', '%d', '%d')", // Also remember to update this...
pName(playerid),
PVar[playerid][pRealName],
PVar[playerid][pFavAdmin],
PVar[playerid][pStatus],
PVar[playerid][pAge],
PVar[playerid][pWantedLevel],
PVar[playerid][pViews]);
mysql_query(Query);
mysql_free_result();
return 1;
}
else return 0;
}
Re: Another problem with mysql - Load info -
JaTochNietDan - 11.08.2011
No, I mean the part where you're formatting a query string and executing it in that function you posted originally, a bit like the function you just posted. Except I don't see any query execution, so how do you expect to gather any results? Also you're using mysql_free_result(); in the function you just posted when there is no result to free...
Re: Another problem with mysql - Load info -
scuess - 11.08.2011
Eh, I don't have anything like that... But how is it possible that the texts are working correct when I want to print them into dialog? Only Age and WantedLevel doesn't work
Re: Another problem with mysql - Load info -
JaTochNietDan - 11.08.2011
pawn Код:
stock LoadPlayerInfo(iPlayer)
{
new
Query[700];
if(mysql_fetch_row(Query))
{
sscanf(Query, "e<p<|>s[24]s[24]s[24]s[24]ddd>", PVar[iPlayer]);
mysql_free_result();
}
return 1;
}
In this snippet of code there is no query and no storing of any results, in which case how can you expect to get any information at all? There needs to be a query executed in order to store a result and then fetch the data. I can't see any problem with this except for the fact that I cannot see a query here, where is it?
Re: Another problem with mysql - Load info -
scuess - 11.08.2011
Oh, my fault, sorry
Код:
stock InitConnection(playerid)
{
new
Query[90],
EscName[MAX_PLAYER_NAME];
mysql_real_escape_string(pName(playerid), EscName);
format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `Nick` = '%s'", EscName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
SendClientMessage(playerid, COLOUR_WHITE, "[!] Loading ur infos from DB...");
LoadPlayerInfo(playerid);
}
else
{
SendClientMessage(playerid, COLOUR_WHITE, "[!] Creating ur table in the DB...");
format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`Nick`) VALUES ('%s')", EscName);
mysql_query(Query);
}
mysql_free_result();
}
Re: Another problem with mysql - Load info -
JaTochNietDan - 11.08.2011
Do some printing so we can debug the code:
pawn Код:
stock LoadPlayerInfo(iPlayer)
{
new
Query[700];
if(mysql_fetch_row(Query))
{
printf("Data returned: %s", Query);
sscanf(Query, "e<p<|>s[24]s[24]s[24]s[24]ddd>", PVar[iPlayer]);
mysql_free_result();
}
return 1;
}
Re: Another problem with mysql - Load info -
scuess - 11.08.2011
Hey guy, it's solved
Thank you very much, I found the misstake because of you :P Thank you :P