Houses Load
#1

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 Cacheresult mysql_query(1"SELECT COUNT(*) FROM houses");
    
printf("%i house(s) loaded"cache_get_row_int(00));
    
cache_delete(result);
    for(new 
0MAX_HOUSESx++)
    {
        
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_GREENHouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 3001);
        
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
Reply
#2

Bumb!
Reply
#3

Bumb again -_-
Reply
#4

You delete the result before using cache functions. Place:
pawn Код:
cache_delete(result);
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:
pawn Код:
owner[MAX_PLAYER_NAME],
Reply
#5

Ok but at the end what should I loop for Max_Houses or what after doing all of these
Reply
#6

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)
Reply
#7

I made it like that and nothing
PHP код:
new Cacheresult mysql_query(1"SELECT * FROM houses");
for(new 
xcache_get_row_count(); != 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], 1MAX_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_GREENHouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 3001);
        
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 ?!
Reply
#8

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 
xcache_get_row_count(); != j; ++x)
    {
        if (
>= 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], 1MAX_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_GREENHouseInfo[x][EntranceX], HouseInfo[x][EntranceY], HouseInfo[x][EntranceZ], 3001);
    }
    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.
Reply
#9

Worked as always kon, Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)