Loading houses MySQL R7 plugin
#1

Hello, I have a problem loading all houses from database.

The function only loads 1 last row from houses table.

Code in OnGameModeInit:
PHP Code:
format(szQueryInputsizeof(szQueryInput), "SELECT * FROM houses");
    
mysql_function_query(connectionszQueryInputtrue"loadHouses"""); 
loadHouses:

PHP Code:
public loadHouses() {
    new 
rowsfields;
    
cache_get_data(rowsfields);
    
    if(
rows) {
        for(new 
0rowsx++) {
            
cache_get_row(x0szQueryOutput); // HouseID
            
strval(szQueryOutput);
            
cache_get_row(x1szQueryOutput); 
            
houseVariables[x][hHouseOwned] = strval(szQueryOutput);
            
cache_get_field_content(x"houseOwner"szQueryOutput);
            
format(houseVariables[x][hHouseOwner],sizeof(szQueryOutput),szQueryOutput);
            
cache_get_field_content(x"houseName"szQueryOutput);
            
format(houseVariables[x][hHouseName],sizeof(szQueryOutput),szQueryOutput);
            
cache_get_row(x4szQueryOutput); 
            
houseVariables[x][hHouseExt][0] = floatstr(szQueryOutput);
            
cache_get_row(x5szQueryOutput); 
            
houseVariables[x][hHouseExt][1] = floatstr(szQueryOutput);
            
cache_get_row(x6szQueryOutput); 
            
houseVariables[x][hHouseExt][2] = floatstr(szQueryOutput);
            
cache_get_row(x7szQueryOutput);
            
houseVariables[x][hHouseInt][0] = floatstr(szQueryOutput);
            
cache_get_row(x8szQueryOutput); 
            
houseVariables[x][hHouseInt][1] = floatstr(szQueryOutput);
            
cache_get_row(x9szQueryOutput);
            
houseVariables[x][hHouseInt][2] = floatstr(szQueryOutput);
            if(
houseVariables[x][hHouseOwned] > 0) {
                switch(
houseVariables[x][hHouseLocked]) {
                    case 
1: {
                        
format(szStringsizeof(szString), "%s\nOwner: %s\nLocked"houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szStringCOLOR_CADETBLUEhouseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -110.0);
                    }
                    case 
2: {
                        
format(szStringsizeof(szString), "%s\nOwner: %s\nLocked"houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szStringCOLOR_CADETBLUEhouseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -110.0);
                    }
                    default: {
                        
format(szStringsizeof(szString), "%s\nOwner: %s\Openedn"houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szStringCOLOR_CADETBLUEhouseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -110.0);
                    }
                }
                
houseVariables[x][hPickupID] = CreateDynamicPickup(127223houseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 00, -1250);
            }
        }
    }

What I'm doing WRONG?
Reply
#2

Fixed:
For everyone who searching houses in loop for MySQL R7:

Change:
PHP Code:
cache_get_row(x0szQueryOutput); // HouseID
            
strval(szQueryOutput); 
to
PHP Code:
cache_get_row(x0szQueryOutput); // HouseID
            
houseVariables[x][hHouseID] = strval(szQueryOutput); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)