Loop issue (SQL, tquerries)
#1

Okay so the problem is simple, the loop will only load "price" and nothing else.
I suck with SQL stuff...

pawn Код:
public OnHouseLoad() {
    new rows, fields,string[128];
    cache_get_data(rows, fields, mysql);
    if(rows > 0) {
        for(new i = 1; i <= cache_get_row_count(); i++)  {
            HouseInfo[i][HousePrice] = cache_get_field_content_int(i,"Price");
            HouseInfo[i][EnterX] = cache_get_field_content_float(i,"EnterX");
            HouseInfo[i][EnterY] = cache_get_field_content_float(i,"EnterY");
            HouseInfo[i][EnterZ] = cache_get_field_content_float(i,"EnterZ");
            HouseInfo[i][ExitX] = cache_get_field_content_float(i,"ExitX");
            HouseInfo[i][ExitY] = cache_get_field_content_float(i,"ExitY");
            HouseInfo[i][ExitZ] = cache_get_field_content_float(i,"ExitZ");
            HouseInfo[i][VirtualWorld] = cache_get_field_content_int(i,"VirtualWorld");
            HouseInfo[i][Interior] = cache_get_field_content_int(i,"InteriorID");
           
            HouseInfo[i][HPickup] = CreatePickup(1272,1,HouseInfo[i][EnterX],HouseInfo[i][EnterY],HouseInfo[i][EnterZ]);
            HousesLoaded++;
        }
    }
    printf("[House System] %i houses were created...", HousesLoaded);
    return true;
}
Reply
#2

Could try
Btw, I'm just going by to what I have similar in my gamemode.
PHP код:
public OnHouseLoad() 
{
    new 
rows, fields;
    
cache_get_data(rows, fields, mysql);
    if(
rows) 
    {
        for(new 
i = 0; i < rows && i < cache_get_row_count(); i++)
        {
            
HouseInfo[i][HousePrice] = cache_get_field_content_int(i,"Price");
            
HouseInfo[i][EnterX] = cache_get_field_content_float(i,"EnterX");
            
HouseInfo[i][EnterY] = cache_get_field_content_float(i,"EnterY");
            
HouseInfo[i][EnterZ] = cache_get_field_content_float(i,"EnterZ");
            
HouseInfo[i][ExitX] = cache_get_field_content_float(i,"ExitX");
            
HouseInfo[i][ExitY] = cache_get_field_content_float(i,"ExitY");
            
HouseInfo[i][ExitZ] = cache_get_field_content_float(i,"ExitZ");
            
HouseInfo[i][VirtualWorld] = cache_get_field_content_int(i,"VirtualWorld");
            
HouseInfo[i][Interior] = cache_get_field_content_int(i,"InteriorID");
            
HouseInfo[i][HPickup] = CreatePickup(1272, 1, HouseInfo[i][EnterX], HouseInfo[i][EnterY], HouseInfo[i][EnterZ]);
            
HousesLoaded++;
        }
        
printf("[House System] %i houses were created...", HousesLoaded);
    }
    else print(
"No houses to be loaded..");
    return 
true;
} 
Also, can you paste where you're calling OnHouseLoad?
Reply
#3

pawn Код:
new query[512];
    for(new i=0; i<=MAX_HOUSES; i++) {
        mysql_format(mysql, query, sizeof(query),"SELECT * FROM `houses` WHERE `ID` = '%i'");
        mysql_tquery(mysql, "SELECT * FROM `Houses`", "OnHouseLoad", "");
    }
if I made huge ass mistake let me know


EDIT: tried your code, still the same shit
Reply
#4

What are you formatting exactly? Paste more.
Reply
#5

Im not sure what else to post, im trying to load houses from the SQL.
AKA im loading this
pawn Код:
enum HINFO
{
    ID,
    Owner[24],
    HouseName[128],
    Float:EnterX,
    Float:EnterY,
    Float:EnterZ,
    Float:ExitX,
    Float:ExitY,
    Float:ExitZ,
    HousePrice,
    Interior,
    VirtualWorld,
    HPickup,
    Text3D:HouseText,
    Owned,
    Garage,
    Locked,
    HouseBank,
}
new HouseInfo[MAX_HOUSES][HINFO], houseid, HousesLoaded;
Reply
#6

PHP код:
for(new i = 0; i < rows && i < cache_get_row_count(); i++) 
Replace with
PHP код:
for(new i = 0; i < rows && i < MAX_HOUSES; i++) 
I don't know what you're formatting so remove the query and the loop and just try
PHP код:
// Under OnGameModeInIt or something
mysql_tquery(mysql, "SELECT * FROM `Houses`", "OnHouseLoad", ""); 
If it doesn't work I'll give it ago on my end and see what I can get loaded.
Reply
#7

Thanks, that actually worked! +rep!
Reply


Forum Jump:


Users browsing this thread: