Loading Problem (MYSQL) - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Loading Problem (MYSQL) (
/showthread.php?tid=208404)
Loading Problem (MYSQL) -
NewbBeginner - 08.01.2011
I have this code:
Code:
function LoadSHouses()
{
for(new id; id < MAX_HOUSES; id++)
{
new DataString[128];
format( Query, sizeof( Query ), "SELECT * FROM ServerHouses WHERE id= '%d'", id);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows())
if(mysql_fetch_row_format(Query,"|"))
{
mysql_fetch_field_row(DataString,"id"); HouseInfo[id][hID] = strval(DataString);
mysql_fetch_field_row(DataString,"Owned"); HouseInfo[id][hOwned] = strval(DataString);
mysql_fetch_field_row(DataString,"Owner"); HouseInfo[id][hOwner] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceX"); HouseInfo[id][hEntranceX] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceY"); HouseInfo[id][hEntranceY] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceZ"); HouseInfo[id][hEntranceZ] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitX"); HouseInfo[id][hExitX] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitY"); HouseInfo[id][hExitY] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitZ"); HouseInfo[id][hExitZ] = strval(DataString);
mysql_fetch_field_row(DataString,"Interior"); HouseInfo[id][hInterior] = strval(DataString);
mysql_fetch_field_row(DataString,"Open"); HouseInfo[id][hOpen] = strval(DataString);
mysql_fetch_field_row(DataString,"Pickup"); HouseInfo[id][hPickup] = strval(DataString);
mysql_fetch_field_row(DataString,"Price"); HouseInfo[id][hPrice] = strval(DataString);
mysql_free_result();
}
if(HouseInfo[id][hOwned] == 0)
{
HouseText[id] = Create3DTextLabel("Sale", COLOR_3D_GOLD, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ] + 0.6, 40.0,0);
HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
}
else if(HouseInfo[id][hOwned] == 1)
{
HouseText[id] = Create3DTextLabel("Has owner", COLOR_3D_GOLD, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ] + 0.6, 40.0,0);
HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
}
}
return 1;
}
I create house ingame, all is perfect in database, but it just doesnt create it after restart.
Re: Loading Problem (MYSQL) -
JaTochNietDan - 08.01.2011
Well I'd imagine the server is freaking out because of all of the queries being executed, that's a lot of queries! Why not just do one query and get the information from that?
For example:
pawn Code:
function LoadSHouses()
{
new DataString[128];
mysql_query("SELECT * FROM `ServerHouses`");
mysql_store_result();
while(mysql_fetch_row_format(Query,"|"))
{
mysql_fetch_field_row(DataString,"id"); HouseInfo[id][hID] = strval(DataString);
mysql_fetch_field_row(DataString,"Owned"); HouseInfo[id][hOwned] = strval(DataString);
mysql_fetch_field_row(DataString,"Owner"); HouseInfo[id][hOwner] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceX"); HouseInfo[id][hEntranceX] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceY"); HouseInfo[id][hEntranceY] = strval(DataString);
mysql_fetch_field_row(DataString,"EntranceZ"); HouseInfo[id][hEntranceZ] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitX"); HouseInfo[id][hExitX] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitY"); HouseInfo[id][hExitY] = strval(DataString);
mysql_fetch_field_row(DataString,"ExitZ"); HouseInfo[id][hExitZ] = strval(DataString);
mysql_fetch_field_row(DataString,"Interior"); HouseInfo[id][hInterior] = strval(DataString);
mysql_fetch_field_row(DataString,"Open"); HouseInfo[id][hOpen] = strval(DataString);
mysql_fetch_field_row(DataString,"Pickup"); HouseInfo[id][hPickup] = strval(DataString);
mysql_fetch_field_row(DataString,"Price"); HouseInfo[id][hPrice] = strval(DataString);
if(HouseInfo[id][hOwned] == 0)
{
HouseText[id] = Create3DTextLabel("Sale", COLOR_3D_GOLD, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ] + 0.6, 40.0,0);
HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
}
else if(HouseInfo[id][hOwned] == 1)
{
HouseText[id] = Create3DTextLabel("Has owner", COLOR_3D_GOLD, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ] + 0.6, 40.0,0);
HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 1, HouseInfo[id][hEntranceX], HouseInfo[id][hEntranceY], HouseInfo[id][hEntranceZ]);
}
}
mysql_free_result();
return 1;
}