23.07.2013, 22:11
Hello, I have a problem loading all houses from database.
The function only loads 1 last row from houses table.
Code in OnGameModeInit:
loadHouses:
What I'm doing WRONG?
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", "");
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);
}
}
}
}