MySQL problem
#1

I made a building system in MySQL but is load every building but the last id wont come up in game here is the code

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

Oh no, please no. /me cries. Learn to use while-loops and use a single query instead of possibly 100+ queries.

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

With this code wont load the building

Код:
SA-MP Dedicated Server
----------------------
v0.3e, ©2005-2012 SA-MP Team

[09:18:03] filterscripts = ""  (string)
[09:18:03] 
[09:18:03] Server Plugins
[09:18:03] --------------
[09:18:03]  Loading plugin: mysql.so
[09:18:03] MySQL: Query thread running. Thread safe: No.
[09:18:03]  SA:MP MySQL Plugin 1.2.1 Loaded.
[09:18:03]   Loaded.
[09:18:03]  Loading plugin: streamer.so
[09:18:03] 

*** Streamer Plugin v2.6.1 by Incognito loaded ***

[09:18:03]   Loaded.
[09:18:03]  Loading plugin: sscanf.so
[09:18:03] 

[09:18:03]  ===============================

[09:18:03]       sscanf plugin loaded.     

[09:18:03]    © 2009 Alex "******" Cole

[09:18:03]    0.3d-R2 500 Players "dnee"

[09:18:03]  ===============================

[09:18:03]   Loaded.
[09:18:03]  Loading plugin: audio.so
[09:18:03] 

*** Audio Plugin v0.5 by Incognito loaded ***

[09:18:03]   Loaded.
[09:18:03]  Loaded 4 plugins.

[09:18:03] 
[09:18:03] Filterscripts
[09:18:03] ---------------
[09:18:03]   Loaded 0 filterscripts.

[09:18:04] OnGameo
[09:18:04] MySQL: Connected (0) to 3802_Hellman @ 127.0.0.1 via TCP/IP. MySQL version 5.0.84.
[09:18:04] AllowAdminTeleport() : function is deprecated. Please see OnPlayerClickMap()
[09:18:04] Job Positions have been loaded
[09:18:04] 400 Houses loaded from database
[09:18:04] 50 Garages loaded from database
[09:18:04] Number of vehicle models: 0
Reply
#4

Listen bro i suggest that you don't even use MYSQL for your script! Because it's VERY annoying and harder than usual. So i suggest that you move on to a script WITHOUT MYSQL.
Reply
#5

So? i will still using MySQL
Reply
#6

Quote:
Originally Posted by Leo Delvecchio
Посмотреть сообщение
Listen bro i suggest that you don't even use MYSQL for your script! Because it's VERY annoying and harder than usual. So i suggest that you move on to a script WITHOUT MYSQL.
Lol come on most of the servers are MySQL and they are having great population. Also there are many benefits of it, without MySQL it is nearly impossible to make a user control panel and retrieving server data.

-FalconX
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)