How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 03.10.2014
So bassicly this is a follow-up thread to a thread I posted yesterday and I'd like to know for example, how to load stuff using a loop, so like it'll load alot of stuff at once, for example: pickups, vehicles, and more.
Here's just a simple code I've attempted to do so yet I don't know how, I'd like someone to fix it and explain to me what he did and how is it supposed to work.
pawn Код:
stock MySQL_LOADvehicles()
{
new query[30];
mysql_format(g_Read, query, sizeof(query), "SELECT * FROM vehicles");
mysql_pquery(g_Read, query, "OnVehicleLoad");
}
forward OnVehicleLoad();
public OnVehicleLoad()
{
for(new i = 0; i < _:Vehicles ; i++)
{
VehInfo[i][VehicleID] = cache_get_field_content_int(i, "VehicleID");
VehInfo[i][RentCash] = cache_get_field_content_int(i, "RentCash");
VehInfo[i][Col1] = cache_get_field_content_int(i, "Col1");
VehInfo[i][Col2] = cache_get_field_content_int(i, "Col2");
VehInfo[i][Model] = cache_get_field_content_int(i, "Model");
VehInfo[i][PosX] = cache_get_field_content_float(i, "PosX");
VehInfo[i][PosY] = cache_get_field_content_float(i, "PosY");
VehInfo[i][PosZ] = cache_get_field_content_float(i, "PosZ");
VehInfo[i][RotZ] = cache_get_field_content_float(i, "RotZ");
VehInfo[i][RentAvailable] = CreateVehicle(VehInfo[i][Model], VehInfo[i][PosX], VehInfo[i][PosY], VehInfo[i][PosZ], VehInfo[i][RotZ], VehInfo[i][Col1], VehInfo[i][Col2], -1);
}
}
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
ranme15 - 03.10.2014
Seems like you've done this well. If it doesn't work, try using cache_get_row.
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 03.10.2014
Alright, I'll try cache_get_row then.
Edit: Nvm, I haven't tested cache_get_row but I've tried to change the code, like used 100 instead of _:Vehicles, and removed the VehInfo[i][RentAvailable] thing, yet still no success.
Could you change my current code with a fixed one so I'll see what you've done there, because I didn't quite understand that whole cache_get_row from the wiki, like tbh the whole wiki thing explains all the functions like shit.
So I didn't really get that.
Plus if someone answers this just know that I won't be able to reply at - at least late night tomorrow (saturday).
Anyways, Zom Kal! (for ranme15)
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 04.10.2014
I am bumping this in order to receive help.
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 05.10.2014
Oh come the fuck on, no one's freal helping me with this shit
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
HyperZ - 05.10.2014
Try something like this:
pawn Код:
forward OnVehicleLoad();
public OnVehicleLoad()
{
for(new i, j = cache_get_row_count(g_Read); i < j; i++) // loop through all the rows that were found
{
VehInfo[i][VehicleID] = cache_get_field_content_int(i, "VehicleID");
VehInfo[i][RentCash] = cache_get_field_content_int(i, "RentCash");
VehInfo[i][Col1] = cache_get_field_content_int(i, "Col1");
VehInfo[i][Col2] = cache_get_field_content_int(i, "Col2");
VehInfo[i][Model] = cache_get_field_content_int(i, "Model");
VehInfo[i][PosX] = cache_get_field_content_float(i, "PosX");
VehInfo[i][PosY] = cache_get_field_content_float(i, "PosY");
VehInfo[i][PosZ] = cache_get_field_content_float(i, "PosZ");
VehInfo[i][RotZ] = cache_get_field_content_float(i, "RotZ");
VehInfo[i][RentAvailable] = CreateVehicle(VehInfo[i][Model], VehInfo[i][PosX], VehInfo[i][PosY], VehInfo[i][PosZ], VehInfo[i][RotZ], VehInfo[i][Col1], VehInfo[i][Col2], -1);
}
}
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 05.10.2014
Quote:
Originally Posted by HyperZ
Try something like this:
pawn Код:
forward OnVehicleLoad(); public OnVehicleLoad() { for(new i, j = cache_get_row_count(g_Read); i < j; i++) // loop through all the rows that were found { VehInfo[i][VehicleID] = cache_get_field_content_int(i, "VehicleID"); VehInfo[i][RentCash] = cache_get_field_content_int(i, "RentCash"); VehInfo[i][Col1] = cache_get_field_content_int(i, "Col1"); VehInfo[i][Col2] = cache_get_field_content_int(i, "Col2"); VehInfo[i][Model] = cache_get_field_content_int(i, "Model"); VehInfo[i][PosX] = cache_get_field_content_float(i, "PosX"); VehInfo[i][PosY] = cache_get_field_content_float(i, "PosY"); VehInfo[i][PosZ] = cache_get_field_content_float(i, "PosZ"); VehInfo[i][RotZ] = cache_get_field_content_float(i, "RotZ");
VehInfo[i][RentAvailable] = CreateVehicle(VehInfo[i][Model], VehInfo[i][PosX], VehInfo[i][PosY], VehInfo[i][PosZ], VehInfo[i][RotZ], VehInfo[i][Col1], VehInfo[i][Col2], -1); } }
|
Alright but wait a second, I think I forgot something, o.o.
I forgot to get the data, like cache_get_data, should I do cache_get_data(i, i);
??
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
HyperZ - 05.10.2014
Quote:
Originally Posted by Ox1gEN
Alright but wait a second, I think I forgot something, o.o.
I forgot to get the data, like cache_get_data, should I do cache_get_data(i, i);
??
|
You forgot about counting the rows that were found in the table.
Check this tutorial:
https://sampforum.blast.hk/showthread.php?tid=505081
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 05.10.2014
Quote:
Originally Posted by HyperZ
|
Mhmm, okay.
I have read that but I still can not get it to work, I have changed the code accordingly yet it still doesn't create a vehicle.
Edit: I have also attempted to print the result yet it doesn't even print it, like there's something that stops it from continouing
Re: How to load stuff from mysql using a loop, to load alot of stuff at once -
Ox1gEN - 07.10.2014
Come on, someone must have an answer for this...