SQL Loading./
#1

I have the code below, but when I use it and call that function, it only loads one vehicle.. Where as it's supposed to load 3 vehicles or however many the player has got?

Could someone help please?

Here's the code:

pawn Код:
stock LoadOwnedCars(playerid)
{
    new query[1024], savingstring[40], newcar, vID;
    format(query, sizeof(query), "SELECT * FROM OwnedVehicles WHERE OwnedVehicleOwner = '%s'", pName(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "OwnedVehicleID"); vID = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleModel"); Vehicles[vID][vModel] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleColor1"); Vehicles[vID][vColor1] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleColor2"); Vehicles[vID][vColor2] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePrice"); Vehicles[vID][vPrice] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleX"); Vehicles[vID][vPosX] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleY"); Vehicles[vID][vPosY] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleZ"); Vehicles[vID][vPosZ] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleA"); Vehicles[vID][vPosA] = floatstr(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleOwner"); strmid(Vehicles[vID][VehicleOwner], savingstring, 0, strlen(savingstring), 24);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePlate"); strmid(Vehicles[vID][VehiclePlate], savingstring, 0, strlen(savingstring), 24);
        mysql_fetch_field_row(savingstring, "OwnedVehiclePaintJob"); Vehicles[vID][VehiclePaintJob] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleLock"); Vehicles[vID][vLocked] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMoney"); Vehicles[vID][vTrunkMoney] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMaterials"); Vehicles[vID][vTrunkMats] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleCocaine"); Vehicles[vID][vTrunkCocaine] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleMoonshine"); Vehicles[vID][vTrunkMoonshine] = strval(savingstring);
        mysql_fetch_field_row(savingstring, "OwnedVehicleFuel"); Vehicles[vID][vFuel] = strval(savingstring);
        newcar = CreateVehicle(Vehicles[vID][vModel], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][vColor1], Vehicles[vID][vColor2], -1);
        format(Vehicles[vID][VehicleOwner], 24, "%s", Vehicles[vID][VehicleOwner]);
        format(Vehicles[vID][VehiclePlate], 32, "%s", Vehicles[vID][VehiclePlate]);
        SetVehicleNumberPlate(newcar, Vehicles[vID][VehiclePlate]);
        SetVehicleToRespawn(newcar);
        OwnedCar(newcar) = vID;
    }
    mysql_free_result();
    return 1;
}
Thanks!
Reply
#2

pawn Код:
stock LoadOwnedCars(playerid)
{
    new query[300], newcar, vID;
    format(query, sizeof(query), "SELECT * FROM OwnedVehicles WHERE OwnedVehicleOwner = '%s'", pName(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_fetch_row(query);
        sscanf(query, "p<|>d", vID);
        sscanf(query, "p<|>{d}ddddffffs[24]s[24]dddddddd", Vehicles[vID][vModel], Vehicles[vID][vColor1], Vehicles[vID][vColor2], Vehicles[vID][vPrice], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][VehicleOwner], Vehicles[vID][VehiclePlate], Vehicles[vID][VehiclePaintJob], Vehicles[vID][vLocked], Vehicles[vID][vTrunkMoney], Vehicles[vID][vTrunkMats], Vehicles[vID][vTrunkCocaine], Vehicles[vID][vTrunkMoonshine], Vehicles[vID][vFuel]);
        newcar = CreateVehicle(Vehicles[vID][vModel], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][vColor1], Vehicles[vID][vColor2], -1);
        format(Vehicles[vID][VehicleOwner], 24, "%s", Vehicles[vID][VehicleOwner]);
        format(Vehicles[vID][VehiclePlate], 32, "%s", Vehicles[vID][VehiclePlate]);
        SetVehicleNumberPlate(newcar, Vehicles[vID][VehiclePlate]);
        SetVehicleToRespawn(newcar);
        OwnedCar(newcar) = vID;
    }
    mysql_free_result();
    return 1;
}
Why in god's name are you using 1024 as a string length for your query?
Reply
#3

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
pawn Код:
stock LoadOwnedCars(playerid)
{
    new query[300], newcar, vID;
    format(query, sizeof(query), "SELECT * FROM OwnedVehicles WHERE OwnedVehicleOwner = '%s'", pName(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        mysql_fetch_row(query);
        sscanf(query, "p<|>d", vID);
        sscanf(query, "p<|>{d}ddddffffs[24]s[24]dddddddd", Vehicles[vID][vModel], Vehicles[vID][vColor1], Vehicles[vID][vColor2], Vehicles[vID][vPrice], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][VehicleOwner], Vehicles[vID][VehiclePlate], Vehicles[vID][VehiclePaintJob], Vehicles[vID][vLocked], Vehicles[vID][vTrunkMoney], Vehicles[vID][vTrunkMats], Vehicles[vID][vTrunkCocaine], Vehicles[vID][vTrunkMoonshine], Vehicles[vID][vFuel]);
        newcar = CreateVehicle(Vehicles[vID][vModel], Vehicles[vID][vPosX], Vehicles[vID][vPosY], Vehicles[vID][vPosZ], Vehicles[vID][vPosA], Vehicles[vID][vColor1], Vehicles[vID][vColor2], -1);
        format(Vehicles[vID][VehicleOwner], 24, "%s", Vehicles[vID][VehicleOwner]);
        format(Vehicles[vID][VehiclePlate], 32, "%s", Vehicles[vID][VehiclePlate]);
        SetVehicleNumberPlate(newcar, Vehicles[vID][VehiclePlate]);
        SetVehicleToRespawn(newcar);
        OwnedCar(newcar) = vID;
    }
    mysql_free_result();
    return 1;
}
Using this the vehicles just don't load..
Reply
#4

Bump.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)