Loading cars, A little help?
#1

Alright, well basically, when it saves to the database, it does save each car correctly, however, when the vehicles load, it only loads 1 vehicle! Weird, huh?

pawn Код:
stock LoadFVehicles()
{
    new QueryString[128];
    mysql_query( "SELECT id, VehicleModel, VehicleColour1, VehicleColour2, Plate, VehicleX, VehicleY, VehicleZ, VehicleAngle, Rank, Faction FROM factionvehicles");
    mysql_store_result();
    new x;
    if(mysql_num_rows() >= 1)
    {
        while(mysql_retrieve_row())
        {
            mysql_get_field("id", QueryString);
            x = strval(QueryString);

            mysql_get_field( "VehicleModel", QueryString);
            VehicleModel[x] = strval( QueryString);

            mysql_get_field( "VehicleColour1", QueryString);
            VehicleColour1[x] = strval( QueryString);

            mysql_get_field( "VehicleColour2", QueryString);
            VehicleColour2[x] = strval( QueryString);

            mysql_get_field( "Plate", VehiclePlate[x]);

            mysql_get_field( "VehicleX", QueryString);
            VehicleX[x] = floatstr( QueryString);

            mysql_get_field( "VehicleY", QueryString);
            VehicleY[x] = floatstr( QueryString);

            mysql_get_field( "VehicleZ", QueryString);
            VehicleZ[x] = floatstr( QueryString);
           
            mysql_get_field( "VehicleX", QueryString);
            VehicleX[x] = floatstr( QueryString);

            mysql_get_field( "Rank", QueryString);
            VehicleRank[x] = strval( QueryString);

            mysql_get_field( "Faction", QueryString);
            VehicleFaction[x] = strval( QueryString);
           
            new vehicleid = CreateVehicle(VehicleModel[x], VehicleX[x], VehicleY[x],VehicleZ[x], VehicleAngle[x], VehicleColour1[x], VehicleColour2[x], -1);
            SetVehicleNumberPlate(x, VehiclePlate[x]);
            mysql_free_result();
        }
     }
    return 1;
}
Reply
#2

Move the mysql_free_result() to the end, right before the return 1

pawn Код:
...
            new vehicleid = CreateVehicle(VehicleModel[x], VehicleX[x], VehicleY[x],VehicleZ[x], VehicleAngle[x], VehicleColour1[x], VehicleColour2[x], -1);
            SetVehicleNumberPlate(x, VehiclePlate[x]);
        }
     }
    mysql_free_result();
    return 1;
}
Reply
#3

Works, thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)