Houses Load -
nezo2001 - 12.06.2015
Idk wtf is happening with me
Here is the full code I've made
PHP код:
#define MAX_HOUSES 1000
enum hInfo
{
HouseID,
Float:EntranceX,
Float:EntranceY,
Float:EntranceZ,
Float:ExitX,
Float:ExitY,
Float:ExitZ,
InsideInt,
owner[128],
owned,
HousePrice,
HouseText[128]
};
new HouseInfo[MAX_HOUSES][hInfo];
And I load it like this
PHP код:
new Cache: result = mysql_query(1, "SELECT COUNT(*) FROM houses");
printf("%i house(s) loaded", cache_get_row_int(0, 0));
cache_delete(result);
for(new x = 0; x < MAX_HOUSES; x++)
{
HouseInfo[x][HouseID] = cache_get_field_content_int(0, "id");
HouseInfo[x][EntranceX] = cache_get_field_content_float(0, "EntranceX");
HouseInfo[x][EntranceY] = cache_get_field_content_float(0, "EntranceY");
HouseInfo[x][EntranceZ] = cache_get_field_content_float(0, "EntranceZ");
HouseInfo[x][ExitX] = cache_get_field_content_float(0, "ExitX");
HouseInfo[x][ExitY] = cache_get_field_content_float(0, "ExitY");
HouseInfo[x][ExitZ] = cache_get_field_content_float(0, "ExitZ");
HouseInfo[x][InsideInt] = cache_get_field_content_int(0, "InsideInt");
cache_get_field_content(0, "owner", HouseInfo[x][owner]);
HouseInfo[x][owned] = cache_get_field_content_int(0, "owned");
HouseInfo[x][HousePrice] = cache_get_field_content_int(0, "price");
cache_get_field_content(0, "text", HouseInfo[x][HouseText]);
Create3DTextLabel(HouseInfo[x][HouseText], COLOR_GREEN, HouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 30, 0, 1);
printf("Info x = %f\nInfo y = %f\nInfo z = %f",HouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ]);
}
And it printed me
Код:
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
x info = 0.0000
y info = 0.0000
z info = 0.0000
//Till forever
And it isn't like that in the database
Re: Houses Load -
nezo2001 - 13.06.2015
Bumb!
Re: Houses Load -
nezo2001 - 13.06.2015
Bumb again -_-
Re: Houses Load -
Konstantinos - 13.06.2015
You delete the result before using cache functions. Place:
at the end (after the loop).
Also I said in your previous thread that if you want to count to use COUNT(*) but selecting all data is different ("SELECT * FROM houses").
You need to loop until rows returned (cache_get_row_count) and not until MAX_HOUSES.
In these:
pawn Код:
cache_get_field_content_int(0, ...
cache_get_field_content_float(0, ...
cache_get_field_content(0, ...
Replace "0" with "x".
Last in cache_get_field_content and enum-array, you need to specify the length:
pawn Код:
cache_get_field_content(x, "owner", HouseInfo[x][owner], 1, MAX_PLAYER_NAME);
and replace in your enum with:
Re: Houses Load -
nezo2001 - 13.06.2015
Ok but at the end what should I loop for Max_Houses or what after doing all of these
Re: Houses Load -
Konstantinos - 13.06.2015
If there are let's say 5 rows and MAX_HOUSES is defined as 50, it will call the functions 45 times without having a result. That's why you loop according to the rows returned:
pawn Код:
for (new i, j = cache_get_row_count(); i != j; ++i)
Re: Houses Load -
nezo2001 - 14.06.2015
I made it like that and nothing
PHP код:
new Cache: result = mysql_query(1, "SELECT * FROM houses");
for(new x, j = cache_get_row_count(); x != j; ++x)
{
HouseInfo[x][HouseID] = cache_get_field_content_int(x, "id");
HouseInfo[x][EntranceX] = cache_get_field_content_float(x, "EntranceX");
HouseInfo[x][EntranceY] = cache_get_field_content_float(x, "EntranceY");
HouseInfo[x][EntranceZ] = cache_get_field_content_float(x, "EntranceZ");
HouseInfo[x][ExitX] = cache_get_field_content_float(x, "ExitX");
HouseInfo[x][ExitY] = cache_get_field_content_float(x, "ExitY");
HouseInfo[x][ExitZ] = cache_get_field_content_float(x, "ExitZ");
HouseInfo[x][InsideInt] = cache_get_field_content_int(x, "InsideInt");
cache_get_field_content(x, "owner", HouseInfo[x][owner], 1, MAX_PLAYER_NAME);
HouseInfo[x][owned] = cache_get_field_content_int(x, "owned");
HouseInfo[x][HousePrice] = cache_get_field_content_int(x, "price");
cache_get_field_content(x, "text", HouseInfo[x][HouseText]);
Create3DTextLabel(HouseInfo[x][HouseText], COLOR_GREEN, HouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 30, 0, 1);
mysql_log(LOG_ALL);
printf("x = %f\ny = %f\nz = %f",HouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ]);
cache_delete(result);
}
}
And it printed
Код:
13:12:31] x = 1419.949951
y = -1640.239990
z = 13.546899
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
[13:12:31] x = 0.000000
y = 0.000000
z = 0.000000
//and more
And there are 148 house in the table ?!
Re: Houses Load -
Konstantinos - 14.06.2015
How is it supposed to know how many times it will loop if you don't execute the query before?
Anyway, I see no point on using non-threaded queries as they are slower and especially when having many rows:
pawn Код:
mysql_tquery(1, "SELECT * FROM houses", "OnHousesLoad", "");
PHP код:
forward OnHousesLoad();
public OnHousesLoad()
{
for(new x, j = cache_get_row_count(); x != j; ++x)
{
if (x >= sizeof HouseInfo) break; // prevent any out of bounds run time error
HouseInfo[x][HouseID] = cache_get_field_content_int(x, "id");
HouseInfo[x][EntranceX] = cache_get_field_content_float(x, "EntranceX");
HouseInfo[x][EntranceY] = cache_get_field_content_float(x, "EntranceY");
HouseInfo[x][EntranceZ] = cache_get_field_content_float(x, "EntranceZ");
HouseInfo[x][ExitX] = cache_get_field_content_float(x, "ExitX");
HouseInfo[x][ExitY] = cache_get_field_content_float(x, "ExitY");
HouseInfo[x][ExitZ] = cache_get_field_content_float(x, "ExitZ");
HouseInfo[x][InsideInt] = cache_get_field_content_int(x, "InsideInt");
cache_get_field_content(x, "owner", HouseInfo[x][owner], 1, MAX_PLAYER_NAME);
HouseInfo[x][owned] = cache_get_field_content_int(x, "owned");
HouseInfo[x][HousePrice] = cache_get_field_content_int(x, "price");
cache_get_field_content(x, "text", HouseInfo[x][HouseText], 1, /* SIZE OF HouseText HERE */);
Create3DTextLabel(HouseInfo[x][HouseText], COLOR_GREEN, HouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 30, 0, 1);
}
return 1;
}
and modify this line:
pawn Код:
cache_get_field_content(x, "text", HouseInfo[x][HouseText], 1, /* SIZE OF HouseText HERE */);
and the size you have in the enum for HouseText.
Re: Houses Load -
nezo2001 - 14.06.2015
Worked as always kon, Thanks!