SA-MP Forums Archive
MySQL problem - 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 problem (/showthread.php?tid=484596)



MySQL problem - Rapeassboi - 31.12.2013

Every building loads but the last building id dosen't why?

pawn Код:
forward LoadBuilding();
public LoadBuilding()
{
    new arrCoords[11][64];
    new sql[80], row[512];
    format(sql, sizeof(sql), "SELECT COUNT(*) FROM Buildings");
    mysql_query(sql);
    mysql_store_result();
    mysql_fetch_row(row);
    totalbuildings = 10;
    mysql_free_result();

    for (new idx=0; idx<totalbuildings; idx++)
    {
        format(sql, sizeof(sql), "SELECT * FROM Buildings WHERE BuildingID=%d", idx);
        mysql_query(sql);
        mysql_store_result();
        if (mysql_num_rows() > 0)
        {
            mysql_fetch_row(row);
            split(row, arrCoords, '|');
            mysql_free_result();
            Building[idx][EnterX] = floatstr(arrCoords[1]);
            Building[idx][EnterY] = floatstr(arrCoords[2]);
            Building[idx][EnterZ] = floatstr(arrCoords[3]);
            Building[idx][PickupID] = strval(arrCoords[4]);
            Building[idx][ExitX] = floatstr(arrCoords[5]);
            Building[idx][ExitY] = floatstr(arrCoords[6]);
            Building[idx][ExitZ] = floatstr(arrCoords[7]);
            strmid(Building[idx][BuildingName], arrCoords[8], 0, strlen(arrCoords[8]), 255);
            Building[idx][ExitInterior] = strval(arrCoords[9]);
            Building[idx][Custom] = strval(arrCoords[10]);

            //Building[idx][PickupID] = CreateStreamPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ],15);
            CreateDynamicPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ], -1, -1, -1, 40.0);
        }
    }
    mysql_free_result();
    printf("%d Buildings loaded from database", totalbuildings);
    return true;
}



Re: MySQL problem - Wizza - 31.12.2013

Learn to use while-loops and use a single query not 100.

pawn Код:
forward LoadBuilding();
public LoadBuilding()
{
    new arrCoords[11][64];
    new row[512], idx;
   
    mysql_query("SELECT * FROM Buildings");
    mysql_store_result();
   
    while(mysql_fetch_row(row))
    {
        split(row, arrCoords, '|');
        Building[idx][EnterX] = floatstr(arrCoords[1]);
        Building[idx][EnterY] = floatstr(arrCoords[2]);
        Building[idx][EnterZ] = floatstr(arrCoords[3]);
        Building[idx][PickupID] = strval(arrCoords[4]);
        Building[idx][ExitX] = floatstr(arrCoords[5]);
        Building[idx][ExitY] = floatstr(arrCoords[6]);
        Building[idx][ExitZ] = floatstr(arrCoords[7]);
        strmid(Building[idx][BuildingName], arrCoords[8], 0, strlen(arrCoords[8]), 255);
        Building[idx][ExitInterior] = strval(arrCoords[9]);
        Building[idx][Custom] = strval(arrCoords[10]);

        //Building[idx][PickupID] = CreateStreamPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ],15);
        CreateDynamicPickup(1239, 1, Building[idx][EnterX], Building[idx][EnterY], Building[idx][EnterZ], -1, -1, -1, 40.0);
        idx++;
    }

    mysql_free_result();
    printf("%d Buildings loaded from database", idx);
    return true;
}



Re: MySQL problem - dusk - 31.12.2013

Perhaps there are more then 10 of them?
pawn Код:
totalbuildings = 10;



Re: MySQL problem - Rapeassboi - 31.12.2013

dusk no its the maximum, Wizza i'm not used to 'while-loops' they are hard to get but thanks its fixed now.


Re: MySQL problem - EliteApple - 31.12.2013

First off, I advice you not using that script. It's very buggy. You're better off writing your own with similiar features. (IBP:RP edit)
Anyways, just change the totalbuildings to 11 instead of 10, if you want to load 100 buildings, put 101. ect.

add me on skype if you need more assistance with the script.

eliteapple1337