SA-MP Forums Archive
Mysql loading only four rows. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql loading only four rows. (/showthread.php?tid=597511)



Mysql loading only four rows. - k2168 - 01.01.2016

I'm making a system of vehicle. and I got a problem while loading rows from mysql.

mysql has 10 rows and when the server trying to load rows from table, it loads only 4 rows.

here's my code.

PHP код:
stock LoadPlayerVehicles()
{
    new 
query[120];
    
    
mysql_format(g_Handle, query, sizeof(query), "SELECT * FROM `vehicles`");
    
mysql_tquery(g_Handle, query, "OnLoadVehicles", "");
    return 
1;
}
public 
OnLoadVehicles()
{
    for(new 
i = 0; i < cache_get_row_count(); i++)
    {
        
g_VehicleInfo[i][vehicle_ModelID]   = cache_get_field_content_int(i, "vehicle_ModelID");
        
g_VehicleInfo[i][vehicle_OwnerID]   = cache_get_field_content_int(i, "vehicle_OwnerID");
        
        
g_VehicleInfo[i][vehicle_Color1]    = cache_get_field_content_int(i, "vehicle_Color1");
        
g_VehicleInfo[i][vehicle_Color2]    = cache_get_field_content_int(i, "vehicle_Color1");
        
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_int(i, "vehicle_ParkX");
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_int(i, "vehicle_ParkY");
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_int(i, "vehicle_ParkZ");
        
g_VehicleInfo[i][vehicle_Angle]    = cache_get_field_content_int(i, "vehicle_Angle");
        
        
/*new vehicle = CreateVehicle();
        SetVehicleNumberPlate(vehicle, plate);*/
    
}
    return 
1;
} 



Re: Mysql loading only four rows. - Stones - 01.01.2016

PHP код:
stock LoadPlayerVehicles() 
{ 
    new 
query[120]; 
     
    
mysql_format(g_Handle, query, sizeof(query), "SELECT * FROM `vehicles`"); 
    
mysql_tquery(g_Handle, query, "OnLoadVehicles", ""); 
    return 
1; 
} 
public 
OnLoadVehicles() 
{ 
    for(new 
i = 0; i < cache_get_row_count(); i++) 
    { 
        
g_VehicleInfo[i][vehicle_ModelID]   = cache_get_field_content_int(i, "vehicle_ModelID"); 
        
g_VehicleInfo[i][vehicle_OwnerID]   = cache_get_field_content_int(i, "vehicle_OwnerID"); 
         
        
g_VehicleInfo[i][vehicle_Color1]    = cache_get_field_content_int(i, "vehicle_Color1"); 
        
g_VehicleInfo[i][vehicle_Color2]    = cache_get_field_content_int(i, "vehicle_Color2"); 
         
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_int(i, "vehicle_ParkX"); 
        
g_VehicleInfo[i][vehicle_ParkY]    = cache_get_field_content_int(i, "vehicle_ParkY"); 
        
g_VehicleInfo[i][vehicle_ParkZ]    = cache_get_field_content_int(i, "vehicle_ParkZ"); 
        
g_VehicleInfo[i][vehicle_Angle]    = cache_get_field_content_int(i, "vehicle_Angle"); 
         
        
/*new vehicle = CreateVehicle(); 
        SetVehicleNumberPlate(vehicle, plate);*/ 
    
} 
    return 
1; 
} 



Re: Mysql loading only four rows. - jlalt - 01.01.2016

PHP код:
public OnLoadVehicles()
{
    for(new 
i = 0; i < cache_get_row_count(); i++)
    {
        
g_VehicleInfo[i][vehicle_ModelID]   = cache_get_row_int(i, field_index, g_Handle);
        
        
g_VehicleInfo[i][vehicle_OwnerID]   = cache_get_row_int(i, field_index, g_Handle);

        
g_VehicleInfo[i][vehicle_Color1]    = cache_get_row_int(i, field_index, g_Handle);
        
g_VehicleInfo[i][vehicle_Color2]    = cache_get_row_int(i, field_index, g_Handle);

        
cache_get_row(i, field_index, g_VehicleInfo[i][vehicle_ParkX], g_Handle, 128);
        
cache_get_row(i, field_index, g_VehicleInfo[i][vehicle_ParkX], g_Handle, 128);
        
cache_get_row(i, field_index, g_VehicleInfo[i][vehicle_ParkX], g_Handle, 128);
        
cache_get_row(i, field_index, g_VehicleInfo[i][vehicle_Angle], g_Handle, 128);

        
/*new vehicle = CreateVehicle();
        SetVehicleNumberPlate(vehicle, plate);*/
    
}
    return 
1;
} 
change field index with your data field index,
note: field index start at 0


Re: Mysql loading only four rows. - PrO.GameR - 01.01.2016

If you have 10 rows and it loads 4, then it crashes on 4 ... See whats wrong with your fourth row, stuff such as accessing an out-of-bound array index will crash a public function, stopping it from loading


Re: Mysql loading only four rows. - nl-videomaster - 01.01.2016

IDK if jlalt's thing worked but rewriting those lines with floats might make sense, as if the number is any diffrent from an integer it won't work. The positions are Float's so retrieving them should be as easy as replacing int with float:
PHP код:
stock LoadPlayerVehicles()
{
    new 
query[120];
    
    
mysql_format(g_Handle, query, sizeof(query), "SELECT * FROM `vehicles`");
    
mysql_tquery(g_Handle, query, "OnLoadVehicles", "");
    return 
1;
}
public 
OnLoadVehicles()
{
    for(new 
i = 0; i < cache_get_row_count(); i++)
    {
        
g_VehicleInfo[i][vehicle_ModelID]   = cache_get_field_content_int(i, "vehicle_ModelID");
        
g_VehicleInfo[i][vehicle_OwnerID]   = cache_get_field_content_int(i, "vehicle_OwnerID");
        
        
g_VehicleInfo[i][vehicle_Color1]    = cache_get_field_content_int(i, "vehicle_Color1");
        
g_VehicleInfo[i][vehicle_Color2]    = cache_get_field_content_int(i, "vehicle_Color1");
        
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_float(i, "vehicle_ParkX");
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_float(i, "vehicle_ParkY");
        
g_VehicleInfo[i][vehicle_ParkX]    = cache_get_field_content_float(i, "vehicle_ParkZ");
        
g_VehicleInfo[i][vehicle_Angle]    = cache_get_field_content_float(i, "vehicle_Angle");
        
        
/*new vehicle = CreateVehicle();
        SetVehicleNumberPlate(vehicle, plate);*/
    
}
    return 
1;
} 
Good luck with your system.