MySQL loading
#1

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;
}
Reply
#2

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.
Reply
#3

yeah try that as the user said above
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)