for(new i=0; i <= MAX_BUILDINGS; i++) {
new query[100];
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `buildings` WHERE `ID`='%d'", i);
mysql_tquery(mysql, query, "LoadBuilding", "i", i);
}
forward LoadBuilding(building);
public LoadBuilding(building) {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(!rows) return 1;
cache_get_field_content(0, "Name", BuildingInfo[building][bName], mysql, 64);
BuildingInfo[building][bOwner] = cache_get_field_content_int(0, "Owner");
BuildingInfo[building][bOwnedBy] = cache_get_field_content_int(0, "OwnedBy");
BuildingInfo[building][bInterior] = cache_get_field_content_int(0, "Interior");
BuildingInfo[building][bVirtualWorld] = cache_get_field_content_int(0, "VirtualWorld");
BuildingInfo[building][bSale] = cache_get_field_content_int(0, "Sale");
BuildingInfo[building][bPrice] = cache_get_field_content_int(0, "Price");
BuildingInfo[building][bID] = cache_get_field_content_int(0, "ID");
BuildingInfo[building][bEntreX] = cache_get_field_content_float(0, "EntreX");
BuildingInfo[building][bEntreY] = cache_get_field_content_float(0, "EntreY");
BuildingInfo[building][bEntreZ] = cache_get_field_content_float(0, "EntreZ");
BuildingInfo[building][bIntX] = cache_get_field_content_float(0, "IntX");
BuildingInfo[building][bIntY] = cache_get_field_content_float(0, "IntY");
BuildingInfo[building][bIntZ] = cache_get_field_content_float(0, "IntZ");
CreateBuildingPickup(building);
return 1;
}
mysql_tquery(mysql, "SELECT * FROM `buildings`", "LoadBuilding");
forward LoadBuilding();
public LoadBuilding() {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(!rows) return 1;
for(new i = 0; i <= rows; i++) {
cache_get_field_content(i, "Name", BuildingInfo[building][bName], mysql, 64);
BuildingInfo[i][bOwner] = cache_get_field_content_int(i, "Owner");
BuildingInfo[i][bOwnedBy] = cache_get_field_content_int(i, "OwnedBy");
BuildingInfo[i][bInterior] = cache_get_field_content_int(i, "Interior");
BuildingInfo[i][bVirtualWorld] = cache_get_field_content_int(i, "VirtualWorld");
BuildingInfo[i][bSale] = cache_get_field_content_int(i, "Sale");
BuildingInfo[i][bPrice] = cache_get_field_content_int(i, "Price");
BuildingInfo[i][bID] = cache_get_field_content_int(i, "ID");
BuildingInfo[i][bEntreX] = cache_get_field_content_float(i, "EntreX");
BuildingInfo[i][bEntreY] = cache_get_field_content_float(i, "EntreY");
BuildingInfo[i][bEntreZ] = cache_get_field_content_float(i, "EntreZ");
BuildingInfo[i][bIntX] = cache_get_field_content_float(i, "IntX");
BuildingInfo[i][bIntY] = cache_get_field_content_float(i, "IntY");
BuildingInfo[i][bIntZ] = cache_get_field_content_float(i, "IntZ");
CreateBuildingPickup(i);
}
return 1;
}
mysql_tquery(mysql, "SELECT * FROM buildings", "LoadBuildings", "");
forward LoadBuildings();
public LoadBuildings() {
for(new i = 0, j = cache_get_row_count(); i != j; i ++) if(i < MAX_BUILDINGS) {
// code
}
return true;
}
Or you could do:
PHP код:
PHP код:
|
Would it be better to send one query and use the loop to store data in the array like this?
|
PHP код:
|
for(new i = 0, j = cache_get_row_count(); i < j && i < MAX_BUILDINGS; i ++)
Unrelated, but pro tip: you can put multiple conditions in the loop header itself. If the condition isn't met the loop stops. Whereas with a nested if the loop keeps on running until it's done, even if there's no more space to store data. So in this case you might write:
PHP код:
|
Could you please describe the difference of your loop and mine if you have the patience?
|
Yes. I praise you for finding this out yourself. Got a tutorial in my sig (don't know which one) that's on this topic, as well.
Unrelated, but pro tip: you can put multiple conditions in the loop header itself. If the condition isn't met the loop stops. Whereas with a nested if the loop keeps on running until it's done, even if there's no more space to store data. So in this case you might write: PHP код:
|
for(new i = 0; i < MAX_BUILDINGS; i ++)
for(new i = 0, j = cache_get_row_count(); i < j && i < MAX_BUILDINGS; i ++)
&& i < MAX_BUILDINGS;
new BuildingInfo[MAX_BUILDINGS][...];
Yes. I praise you for finding this out yourself. Got a tutorial in my sig (don't know which one) that's on this topic, as well.
Unrelated, but pro tip: you can put multiple conditions in the loop header itself. If the condition isn't met the loop stops. Whereas with a nested if the loop keeps on running until it's done, even if there's no more space to store data. So in this case you might write: PHP код:
|
Neither loops are related to each other. The first loop will keep on looping and will continue to assign NULL data to the variables even after it passed the amount of rows you have because you're not taking the row amount in consideration.
The second loop will continue to loop for i < j AND i < MAX_BUILDINGS. You can't exceed MAX_BUILDINGS because I'm sure that your variable to access the enum is a 2D array of which the first set is limited by MAX_BUILDINGS: PHP код:
|