[MYSQL] Selencting only specific rows
#1

Hi guys well, i trying to select only the rows that have the users, userid on them to give the player his weapons that were saved. I am using MySQL R5. Heres what ive tried:

pawn Код:
public OnLoadPlayerWeapons(playerid)
{
    new
        weaponid,
        MySQLQuery[100],
        temp[50],
        row[4000],
        query[300],
        ammo;
        format(MySQLQuery, sizeof(MySQLQuery), "SELECT * FROM ginklai WHERE userid = '%d'", GetPVarInt(playerid, "AccID"));
        mysql_query(MySQLQuery);
        mysql_store_result();
        new queryResult = mysql_query(MySQLQuery);
        if (!queryResult) {
        printf("Query failed, errno %d", mysql_errno());
        } else {
        print("Apparently query succeeded");
        }

        while(mysql_fetch_row_format(MySQLQuery, "|"))
        {
            mysql_fetch_field_row(temp, "weaponid");    weaponid      = strval(temp);
            mysql_fetch_field_row(temp, "Ammo");      ammo      = strval(temp);
            GivePlayerWeapon(playerid, weaponid, ammo);
        }
//      }
       
        mysql_free_result();

 /*       if(!(0 <= weaponid <= 46)) // check if weapon is valid (should be)
        {
            printf("[info] Warning: OnLoadPlayerWeapons - Unknown weaponid '%d'. Skipping.", weaponid);
            continue;
        }*/


       // GivePlayerWeapon(playerid, weaponid, ammo);
//    }
    return;
}
I tried this, but it doesnt seem to work at all. Can anyone tell me whats the problem? Thank you.
Reply
#2

Код:
public OnLoadPlayerWeapons(playerid)
{
   new
        weaponid,
        MySQLQuery[256],
        temp[50],
        ammo;
        format(MySQLQuery, sizeof(MySQLQuery), "SELECT weaponid,ammo FROM ginklai WHERE userid = '%d'", GetPVarInt(playerid, "AccID"));
        mysql_query(MySQLQuery);
        mysql_store_result();
        while(mysql_fetch_row_format(MySQLQuery, "|"))
        {
            mysql_fetch_field_row(temp, "weaponid");    weaponid = strval(temp);
            mysql_fetch_field_row(temp, "ammo");      ammo = strval(temp);
            GivePlayerWeapon(playerid, weaponid, ammo);
        }
        mysql_free_result();
   return 1;
}
Try This
Reply
#3

Since you're already using a "callback" for when player weapons are loaded, why not convert to threaded queries? They don't lag the server while waiting for the result, are easier to deal with and newer version usually means bug fixes.
No one will help you with this I believe, we are moving forward and so should you.
As to actually being helpful I'll say go read one of the many tutorials and scripts on how to use a newer MySQL plugin(R33+).
Reply
#4

Yeah i am going to try to convert to R33+, i think its going to be hard for me tho.
Reply


Forum Jump:


Users browsing this thread: