Splitting MySQL results.
#1

Hey,

When I read in 2-3 (Sometimes more) rows from a database they are not being split into 3 separate variables(With respective arrays).

Here is the code:

pawn Код:
stock loadplayervehicles(iPlayer)
{
    for(new i=0; i<4; i++)
    {
        DestroyVehicle(ownedvehicle[iPlayer][i]);
        ResetVVar(ownedvehicle[iPlayer][i]); // Restores all vehicle relative variables to their default
        ownedvehicle[iPlayer][i] = 0; // This basically makes the player own "0" cars when they log out
    }
    new Query[700];
    format(Query, sizeof(Query), "SELECT * FROM `vehicleinfo` WHERE `vowner` = '%s'", pName(iPlayer));
    mysql_query(Query);
    mysql_store_result();
    new nextveh;
    ownedveh[iPlayer] = 0;
    if(mysql_num_rows()) // I did have a for loop in here to add all 3 vehicles but it didn't work at all.
    {
        mysql_fetch_row_format(Query, "|");
        for(new i=0; i<MAX_VEHICLES; i++)
        {
            if(!IsValidVehicle(i)) // Adds the vehicle into a free vehicle slot
            {
                nextveh = i;
                sscanf(Query, "p<|>e<s[32]ds[32]ds[7]ddffffddfddddddddddddddddddddddddddd>", VVar[vehicle[nextveh]]);
                ownedvehicle[iPlayer][ownedveh[iPlayer]] = vehicle[nextveh];
                new plate[7];
                format(plate,sizeof(plate), VVar[vehicle[nextveh]][vplate]);
                SetVehicleNumberPlate(vehicle[nextveh], plate);
                vehicle[nextveh] = CreateVehicle(VVar[vehicle[nextveh]][vmodel], VVar[vehicle[nextveh]][vx], VVar[vehicle[nextveh]][vy], VVar[vehicle[nextveh]][vz], VVar[vehicle[nextveh]][vangle], VVar[vehicle[nextveh]][vcolour1], VVar[vehicle[nextveh]][vcolour2], 0); // Adds the vehicle data into the respective variables.
                ownedveh[iPlayer]++;
                break;
            }
        }
    }
    ownedveh[iPlayer] = 0;
    return 1;
}
Basically, the FIRST vehicle spawns (If there is 2-3) and the rest don't. I did have a for loop to have the variable assignment 3 times (1 per player car), however it didn't work at all..

Can someone please explain what I'm doing wrong?
Reply


Messages In This Thread
Splitting MySQL results. - by vIBIENNYx - 24.01.2013, 10:22
Re: Splitting MySQL results. - by AndreT - 24.01.2013, 10:29
Re: Splitting MySQL results. - by vIBIENNYx - 24.01.2013, 10:33

Forum Jump:


Users browsing this thread: 3 Guest(s)