MySQL R34 - Only 1 row is being fetched
#1

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.
Reply
#2

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);
        }
    }
}
Reply
#3

Thank you very much, I am glad i learnt something new, really appreciate it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)