MySQL R34 - Only 1 row is being fetched - 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 R34 - Only 1 row is being fetched (
/showthread.php?tid=537525)
MySQL R34 - Only 1 row is being fetched -
MikeEd - 16.09.2014
pawn Код:
stock LoadHouses()
{
new LoadHouseQuery[50];
format(LoadHouseQuery, sizeof(LoadHouseQuery), "SELECT * FROM `houses`");
mysql_function_query(handle, LoadHouseQuery, false, "OnHousesLoad","");
}
forward OnHousesLoad();
public OnHousesLoad()
{
new idx;
new rows, fields;
cache_get_data(rows, fields, handle);
if(rows)
{
idx++;
//data is fetched here
HouseInfo[i][House_ID] = cache_get_row_int(0,0,handle);
//pickups and 3d label created
HouseInfo[i][PickupID] = CreatePickup(1272, 1, HouseInfo[i][Position][0], HouseInfo[i][Position][1], HouseInfo[i][Position][2], 0);
}
}
I've tried swithcing stuff but it doesn't work. I have 32 rows of data but only the 1st one loads. Am i doing anything wrong?
Help will be appreciated.
Re: MySQL R34 - Only 1 row is being fetched -
Kirollos - 16.09.2014
You need to loop through rows and fetch them, all what you were doing is fetching row ID 0 only.
pawn Код:
stock LoadHouses()
{
new LoadHouseQuery[50];
format(LoadHouseQuery, sizeof(LoadHouseQuery), "SELECT * FROM `houses`");
mysql_function_query(handle, LoadHouseQuery, false, "OnHousesLoad","");
}
forward OnHousesLoad();
public OnHousesLoad()
{
new rows, fields;
cache_get_data(rows, fields, handle); // get amount of rows & fields
if(rows) // If we had rows
{
for(new i; i != rows; i++) // i is row id
{
//data is fetched here
HouseInfo[i][House_ID] = cache_get_row_int(i,0,handle); // ID, i = row id, 0 = field id
// I believe you should fetch your Position, etc.. here.
//-------------------------------------------------------
//pickups and 3d label created
HouseInfo[i][PickupID] = CreatePickup(1272, 1, HouseInfo[i][Position][0], HouseInfo[i][Position][1], HouseInfo[i][Position][2], 0);
}
}
}
Re: MySQL R34 - Only 1 row is being fetched -
MikeEd - 16.09.2014
Thank you very much, I am glad i learnt something new, really appreciate it.