SA-MP Forums Archive
Loading houses MySQL R7 plugin - 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)
+--- Thread: Loading houses MySQL R7 plugin (/showthread.php?tid=453131)



Loading houses MySQL R7 plugin - Ld Est Ld - 23.07.2013

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(szQueryInput, sizeof(szQueryInput), "SELECT * FROM houses");
    
mysql_function_query(connection, szQueryInput, true, "loadHouses", ""); 
loadHouses:

PHP Code:
public loadHouses() {
    new 
rows, fields;
    
cache_get_data(rows, fields);
    
    if(
rows) {
        for(new 
x = 0; x < rows; x++) {
            
cache_get_row(x, 0, szQueryOutput); // HouseID
            
x = strval(szQueryOutput);
            
cache_get_row(x, 1, szQueryOutput); 
            
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(x, 4, szQueryOutput); 
            
houseVariables[x][hHouseExt][0] = floatstr(szQueryOutput);
            
cache_get_row(x, 5, szQueryOutput); 
            
houseVariables[x][hHouseExt][1] = floatstr(szQueryOutput);
            
cache_get_row(x, 6, szQueryOutput); 
            
houseVariables[x][hHouseExt][2] = floatstr(szQueryOutput);
            
cache_get_row(x, 7, szQueryOutput);
            
houseVariables[x][hHouseInt][0] = floatstr(szQueryOutput);
            
cache_get_row(x, 8, szQueryOutput); 
            
houseVariables[x][hHouseInt][1] = floatstr(szQueryOutput);
            
cache_get_row(x, 9, szQueryOutput);
            
houseVariables[x][hHouseInt][2] = floatstr(szQueryOutput);
            if(
houseVariables[x][hHouseOwned] > 0) {
                switch(
houseVariables[x][hHouseLocked]) {
                    case 
1: {
                        
format(szString, sizeof(szString), "%s\nOwner: %s\nLocked", houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szString, COLOR_CADETBLUE, houseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
                    }
                    case 
2: {
                        
format(szString, sizeof(szString), "%s\nOwner: %s\nLocked", houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szString, COLOR_CADETBLUE, houseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
                    }
                    default: {
                        
format(szString, sizeof(szString), "%s\nOwner: %s\Openedn", houseVariables[x][hHouseName], houseVariables[x][hHouseOwner]);
                        
houseVariables[x][hLabelID] = CreateDynamic3DTextLabel(szString, COLOR_CADETBLUE, houseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
                    }
                }
                
houseVariables[x][hPickupID] = CreateDynamicPickup(1272, 23, houseVariables[x][hHouseExt][0], houseVariables[x][hHouseExt][1], houseVariables[x][hHouseExt][2], 0, 0, -1, 250);
            }
        }
    }
} 
What I'm doing WRONG?


Re: Loading houses MySQL R7 plugin - Ld Est Ld - 24.07.2013

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

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