MySQL loading - 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: MySQL loading (
/showthread.php?tid=467478)
MySQL loading -
Burning - 03.10.2013
Hello, I'm mading some script and I have problems, I dunno, maybe that's SQL problem but all columns when player tries to load goes to default value
Код HTML:
stock MySQL_Load(playerid)
{
new
Float: pos[3], // 0,1,2 - pozicija;
fetch[16],
Query[256];
format(Query, sizeof(Query), "SELECT * FROM `zaidejai` WHERE vardas = '%s'", GetPlayerNameEx(playerid));
mysql_query(Query);
mysql_store_result();
mysql_retrieve_row();
mysql_fetch_field_row( fetch, "x" );
pos[0] = floatstr(fetch);
mysql_fetch_field_row( fetch, "y" );
pos[1] = floatstr(fetch);
mysql_fetch_field_row( fetch, "z" );
pos[2] = floatstr(fetch);
SetPlayerPos( playerid, pos[0], pos[1], pos[2] + 0.75);
mysql_fetch_field_row( fetch,"pLytis" ); playerData[playerid][pLytis] = strval(fetch);
mysql_fetch_field_row( fetch,"pAdmin" ); playerData[playerid][pAdmin] = strval(fetch);
mysql_fetch_field_row( fetch,"pVip" ); playerData[playerid][pVip] = strval(fetch);
mysql_fetch_field_row( fetch,"pAdmin" ); playerData[playerid][pAdmin] = strval(fetch);
mysql_fetch_field_row( fetch,"skin" ); playerData[playerid][pSkin] = strval(fetch); SetPlayerSkin(playerid, playerData[playerid][pSkin]);
mysql_fetch_field_row( fetch,"pinigai" ); playerData[playerid][pPinigai] = strval(fetch); GivePlayerMoney(playerid, playerData[playerid][pPinigai]);
mysql_fetch_field_row( fetch,"patirtis" ); playerData[playerid][pPatirtis] = strval(fetch); SetPlayerScore(playerid, playerData[playerid][pPatirtis]);
new Float: HP,
Float: ARM;
mysql_fetch_field_row( fetch,"hp" ); HP = floatstr( fetch ); SetPlayerHealth( playerid, HP);
mysql_fetch_field_row( fetch,"armour" ); ARM = floatstr( fetch ); SetPlayerArmour( playerid, ARM);
mysql_free_result();
printf("Pakrautas юaidлjas. [%s]", GetPlayerNameEx(playerid));
return 1;
}
Re: MySQL loading - Emmet_ - 03.10.2013
Maybe try this?
pawn Код:
stock MySQL_Load(playerid)
{
new
Float: pos[3], // 0,1,2 - pozicija;
fetch[16],
Query[256];
format(Query, sizeof(Query), "SELECT * FROM `zaidejai` WHERE vardas = '%s'", GetPlayerNameEx(playerid));
mysql_query(Query);
mysql_store_result();
while (mysql_retrieve_row())
{
mysql_fetch_field_row( fetch, "x" );
pos[0] = floatstr(fetch);
mysql_fetch_field_row( fetch, "y" );
pos[1] = floatstr(fetch);
mysql_fetch_field_row( fetch, "z" );
pos[2] = floatstr(fetch);
SetPlayerPos( playerid, pos[0], pos[1], pos[2] + 0.75);
mysql_fetch_field_row( fetch,"pLytis" ); playerData[playerid][pLytis] = strval(fetch);
mysql_fetch_field_row( fetch,"pAdmin" ); playerData[playerid][pAdmin] = strval(fetch);
mysql_fetch_field_row( fetch,"pVip" ); playerData[playerid][pVip] = strval(fetch);
mysql_fetch_field_row( fetch,"pAdmin" ); playerData[playerid][pAdmin] = strval(fetch);
mysql_fetch_field_row( fetch,"skin" ); playerData[playerid][pSkin] = strval(fetch); SetPlayerSkin(playerid, playerData[playerid][pSkin]);
mysql_fetch_field_row( fetch,"pinigai" ); playerData[playerid][pPinigai] = strval(fetch); GivePlayerMoney(playerid, playerData[playerid][pPinigai]);
mysql_fetch_field_row( fetch,"patirtis" ); playerData[playerid][pPatirtis] = strval(fetch); SetPlayerScore(playerid, playerData[playerid][pPatirtis]);
mysql_fetch_field_row( fetch,"hp" ); SetPlayerHealth( playerid, floatstr( fetch ));
mysql_fetch_field_row( fetch,"armour" ); SetPlayerArmour( playerid, floatstr( fetch ));
}
mysql_free_result();
printf("Pakrautas юaidлjas. [%s]", GetPlayerNameEx(playerid));
return 1;
}
You need to use
mysql_retrieve_row each time you fetch a row, so it can move on to the next pointer.
Re: MySQL loading -
Blueflash123 - 04.10.2013
yeah try that as the user said above
Re: MySQL loading -
Scenario - 04.10.2013
yeah try that as the user said above the user that posted above me
wait, whut?
-_- pro tip: if you don't know how to use MySQL, DON'T USE IT