forward LoadHouses(); public LoadHouses() { for(new i=1; i<=MAX_HOUSES; i++) { new query[128]; mysql_format(mysql, query, sizeof(query), "SELECT * FROM `"HouseTable"` WHERE `ID`='%i'", i); mysql_tquery(mysql, query, "OnLoadHouses", ""); } }
forward OnLoadHouses(); public OnLoadHouses() { for(new i=1; i<=MAX_HOUSES; i++) { new savingstring[400], lString[500]; cache_get_field_content(0, "ID", savingstring), hInfo[i][HID] = strval(savingstring); cache_get_field_content(0, "Owner", hInfo[i][HID], mysql); cache_get_field_content(0, "Owned", savingstring), hInfo[i][Owned] = strval(savingstring); cache_get_field_content(0, "Locked", savingstring), hInfo[i][Locked] = strval(savingstring); cache_get_field_content(0, "Price", savingstring), hInfo[i][Price] = strval(savingstring); cache_get_field_content(0, "OX", savingstring), hInfo[i][OX] = strval(savingstring); cache_get_field_content(0, "OY", savingstring), hInfo[i][OY] = strval(savingstring); cache_get_field_content(0, "OZ", savingstring), hInfo[i][OZ] = strval(savingstring); cache_get_field_content(0, "World", savingstring), hInfo[i][World] = strval(savingstring); cache_get_field_content(0, "OnSale", savingstring), hInfo[i][OnSale] = strval(savingstring); cache_get_field_content(0, "InteriorID", savingstring), hInfo[i][InteriorID] = strval(savingstring); if(hInfo[i][OnSale] == 0 ) { switch(hInfo[i][Owned]) { case 0: { format(lString, sizeof(lString), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", hInfo[i][Price]); hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0x00B9FFFF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0); hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 31, -1); hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0); } case 1: { format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Locked: %s", hInfo[i][Owner], (hInfo[i][Locked] == 1) ? ("Yes") : ("No")); hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xFF0000FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0); hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0); } } CreatedHouses++; } if(hInfo[i][OnSale] == 1) { format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse On Sale: Yes", hInfo[i][Owner], hInfo[i][Price]); hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xD65418FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0); hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 32, -1); hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0); CreatedHouses++; } } printf("[House System] %i houses were created...", CreatedHouses); }
Why aren't you just using one select query instead of selecting everything separately by an ID?
For your problem, try to remove the apostrophe symbol in your select query where `ID` = '%i', should be: `ID` = %i |
forward LoadHouses();
public LoadHouses()
{
mysql_tquery(mysql, "SELECT * FROM `HouseTable`", "OnLoadHouses");
return 1;
}
forward OnLoadHouses();
public OnLoadHouses()
{
for(new i = 1; i <= cache_get_row_count(); i++)
{
new
savingstring[400],
lString[500];
cache_get_field_content(0, "ID", savingstring), hInfo[i][HID] = strval(savingstring);
cache_get_field_content(0, "Owner", hInfo[i][HID], mysql);
cache_get_field_content(0, "Owned", savingstring), hInfo[i][Owned] = strval(savingstring);
cache_get_field_content(0, "Locked", savingstring), hInfo[i][Locked] = strval(savingstring);
cache_get_field_content(0, "Price", savingstring), hInfo[i][Price] = strval(savingstring);
cache_get_field_content(0, "OX", savingstring), hInfo[i][OX] = strval(savingstring);
cache_get_field_content(0, "OY", savingstring), hInfo[i][OY] = strval(savingstring);
cache_get_field_content(0, "OZ", savingstring), hInfo[i][OZ] = strval(savingstring);
cache_get_field_content(0, "World", savingstring), hInfo[i][World] = strval(savingstring);
cache_get_field_content(0, "OnSale", savingstring), hInfo[i][OnSale] = strval(savingstring);
cache_get_field_content(0, "InteriorID", savingstring), hInfo[i][InteriorID] = strval(savingstring);
if(hInfo[i][OnSale] == 0 )
{
switch(hInfo[i][Owned])
{
case 0:
{
format(lString, sizeof(lString), "House Owned: No\nHouse Owner: None\nHouse Price: $%i", hInfo[i][Price]);
hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0x00B9FFFF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 31, -1);
hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
}
case 1:
{
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Locked: %s", hInfo[i][Owner], (hInfo[i][Locked] == 1) ? ("Yes") : ("No"));
hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xFF0000FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
}
}
CreatedHouses++;
}
if(hInfo[i][OnSale] == 1)
{
format(lString, sizeof(lString),"House Owned: Yes\nHouse Owner: %s\nHouse Price: $%i\nHouse On Sale: Yes", hInfo[i][Owner], hInfo[i][Price]);
hInfo[i][Label] = CreateDynamic3DTextLabel(lString, 0xD65418FF, hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ]+0.5, 36.0);
hInfo[i][Icon] = CreateDynamicMapIcon(hInfo[i][OX], hInfo[i][OY], hInfo[i][OZ], 32, -1);
hInfo[i][EnterPickup] = CreateDynamicPickup(1273, 23, hInfo[i][OX],hInfo[i][OY], hInfo[i][OZ], -1, -1, -1, 36.0);
CreatedHouses++;
}
}
printf("[House System] %i houses were created...", CreatedHouses);
return 1;
}
hi
you don't need to loop between house ids ! just select all rows and then catche them i'll edit your code: pawn Код:
and i have a question! why you use "varchar" type for all columns ? ![]() you don't need it. use integers + floats for integers and floats ![]() for example: cache_get_field_content(0, "Locked", savingstring), hInfo[i][Locked] = strval(savingstring); "Locked" column will be only 1 or 0. you don't need use varchare type and then use strval ! or for positions ! edit your database + this function good luck buddy |