LoadBuildings()
{
new DB_Query[256], string[120];
for(new i = 0; i < MAX_BUILDINGS; i++)
{
mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `Buildings` WHERE `ID` = %d", i);
mysql_query(Database, DB_Query);
cache_get_value_int(0, "ID", BuildingInfo[i][ID]);
cache_get_value(0, "Owner", BuildingInfo[i][bOwner], 24);
cache_get_value(0, "Name", BuildingInfo[i][bName], 120);
cache_get_value_int(0, "VirtualWorld", BuildingInfo[i][bVW]);
cache_get_value_int(0, "Pickup", BuildingInfo[i][bPickup]);
cache_get_value_int(0, "InteriorID", BuildingInfo[i][bInt]);
cache_get_value_float(0, "EntranceX", BuildingInfo[i][bEntranceX]);
cache_get_value_float(0, "EntranceY", BuildingInfo[i][bEntranceY]);
cache_get_value_float(0, "EntranceZ", BuildingInfo[i][bEntranceZ]);
cache_get_value_float(0, "ExitX", BuildingInfo[i][bExitX]);
cache_get_value_float(0, "ExitY", BuildingInfo[i][bExitY]);
cache_get_value_float(0, "ExitZ", BuildingInfo[i][bExitZ]);
buildings[BuildingInfo[i][ID]] = CreatePickup(BuildingInfo[i][bPickup], 1, BuildingInfo[i][bEntranceX], BuildingInfo[i][bEntranceY], BuildingInfo[i][bEntranceZ], 0);
format(string, sizeof(string), ""COL_LIGHTBLUE"%s\n"COL_WHITE"-----\n"COL_LIGHTBLUE"Owned by: "COL_WHITE"%s", BuildingInfo[i][bName], BuildingInfo[i][bOwner]);
buildings3d[BuildingInfo[i][ID]] = Create3DTextLabel(string, COLOR_WHITE, BuildingInfo[i][bEntranceX], BuildingInfo[i][bEntranceY], BuildingInfo[i][bEntranceZ], 15.0, 0, 0);
}
return 1;
}
LoadBuildings()
{
mysql_tquery(Database, "SELECT * FROM Buildings LIMIT" #MAX_BUILDINGS, "OnBuildingsAvailable");
}
public OnBuildingsAvailable()
{
new rows;
cache_get_row_count(rows);
for(new i; i < rows; i++)
{
cache_get_value_int(i, "ID", BuildingInfo[i][ID]);
// etc
}
}
This is a horrible way to load multiple rows. Instead of sending 100 queries and retrieving one result at a time, send one query and retrieve all results simultaneously. Also you are not freeing the result here which leads to memory leaks.
PHP код:
|