SA-MP Forums Archive
While there's a next row (in MySQL R33) - 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: While there's a next row (in MySQL R33) (/showthread.php?tid=541877)



While there's a next row (in MySQL R33) - Neil. - 15.10.2014

fixed.


Re: While there's a next row (in MySQL R33) - Neil. - 15.10.2014

double post. sorry


Re: While there's a next row (in MySQL R33) - Chenko - 15.10.2014

No, you need to use a loop as there is no function to go to the next row. A while loop works pretty well for this. Try something like this:

pawn Код:
public OnHouseLoad()
{
    new rows, fields, idx;
    cache_get_data(rows, fields, mysql);
   
    if(rows)
    {
        while(idx < rows)
        {
            HouseCount++;
            houseInfo[HouseCount][slots] = cache_get_field_content_int(idx, "slots");
            houseInfo[HouseCount][ownerid] = cache_get_field_content_int(idx, "ownerid");
            houseInfo[HouseCount][price] = cache_get_field_content_int(idx, "price");
           
            houseInfo[HouseCount][house_x] = cache_get_field_content_float(idx, "house_x");
            houseInfo[HouseCount][house_y] = cache_get_field_content_float(idx, "house_y");
            houseInfo[HouseCount][house_z] = cache_get_field_content_float(idx, "house_z");
           
            if(ownerid != -1)
            {
                mysql_format(mysql, query, sizeof(query), "SELECT username FROM accounts WHERE id = %d", ownerid);
                mysql_tquery(mysql, query, "GetNameFromID", "i", ownerid);
            }
            else
            {
                houseInfo[HouseCount][ownername] = GetNameFromID(
            }
            idx++;
        }
    }
    return 1;
}



Re: While there's a next row (in MySQL R33) - Neil. - 15.10.2014

Quote:
Originally Posted by Chenko
Посмотреть сообщение
No, you need to use a loop as there is no function to go to the next row. A while loop works pretty well for this. Try something like this:

pawn Код:
public OnHouseLoad()
{
    new rows, fields, idx;
    cache_get_data(rows, fields, mysql);
   
    if(rows)
    {
        while(idx < rows)
        {
            HouseCount++;
            houseInfo[HouseCount][slots] = cache_get_field_content_int(idx, "slots");
            houseInfo[HouseCount][ownerid] = cache_get_field_content_int(idx, "ownerid");
            houseInfo[HouseCount][price] = cache_get_field_content_int(idx, "price");
           
            houseInfo[HouseCount][house_x] = cache_get_field_content_float(idx, "house_x");
            houseInfo[HouseCount][house_y] = cache_get_field_content_float(idx, "house_y");
            houseInfo[HouseCount][house_z] = cache_get_field_content_float(idx, "house_z");
           
            if(ownerid != -1)
            {
                mysql_format(mysql, query, sizeof(query), "SELECT username FROM accounts WHERE id = %d", ownerid);
                mysql_tquery(mysql, query, "GetNameFromID", "i", ownerid);
            }
            else
            {
                houseInfo[HouseCount][ownername] = GetNameFromID(
            }
            idx++;
        }
    }
    return 1;
}
Cheers!