MySQL Doesn't load houses
#1

It saves successfully without errors but it doesn't load weirdly enough..?

MYSQL LOG
Quote:

[13:33:59] [DEBUG] cache_get_data - connection: 1
[13:33:59] [WARNING] cache_get_data - no active cache
[13:33:59] [DEBUG] mysql_tquery - connection: 1, query: "SELECT * FROM `houses` WHERE `ID` = '0'", callback: "OnLoadHouses", format: "(null)"
[13:33:59] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[13:33:59] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[13:33:59] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[13:33:59] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:33:59] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:33:59] [DEBUG] CMySQLQuery::Execute[OnLoadHouses] - starting query execution
[13:33:59] [DEBUG] CMySQLConnection::Connect - connection was successful
[13:33:59] [DEBUG] CMySQLQuery::Execute[OnLoadHouses] - query was successfully executed within 0.413 milliseconds
[13:33:59] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[13:33:59] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[13:33:59] [DEBUG] Calling callback "OnLoadHouses"..
[13:33:59] [DEBUG] cache_get_data - connection: 1
[13:33:59] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called

SCRIPT USED FOR LOADING
pawn Код:
stock LoadHouses()
{
    new rows, fields, result[5], query[300];
    cache_get_data(rows, fields);
    if(rows)
    {
        cache_get_field_content(0, "ID", result);
        g_HouseInfo[HouseID][hSQLid] = strval(result);
    }
    format(query, sizeof query, "SELECT * FROM `houses` WHERE `ID` = '%d'", HouseID);
    mysql_function_query(g_Handle, query, true, "OnLoadHouses", "");
    return 1;
}
pawn Код:
forward OnLoadHouses();
public OnLoadHouses()
{
    new rows, fields, result[129], string[128];
    cache_get_data(rows, fields);
    if(rows != 0)
    {
        cache_get_field_content(0, "Owner", result), format(g_HouseInfo[HouseID][hOwner], 24, result);
        cache_get_field_content(0, "OwnerID", result), g_HouseInfo[HouseID][hOwnerid] = strval(result);
        cache_get_field_content(0, "EnPosX", result), g_HouseInfo[HouseID][hEnPosX] = floatstr(result);
        cache_get_field_content(0, "EnPosY", result), g_HouseInfo[HouseID][hEnPosY] = floatstr(result);
        cache_get_field_content(0, "EnPosZ", result), g_HouseInfo[HouseID][hEnPosZ] = floatstr(result);
        cache_get_field_content(0, "ExPosX", result), g_HouseInfo[HouseID][hExPosX] = floatstr(result);
        cache_get_field_content(0, "ExPosY", result), g_HouseInfo[HouseID][hExPosY] = floatstr(result);
        cache_get_field_content(0, "ExPosZ", result), g_HouseInfo[HouseID][hExPosZ] = floatstr(result);
        cache_get_field_content(0, "Interior", result), g_HouseInfo[HouseID][hInterior] = strval(result);
        cache_get_field_content(0, "World", result), g_HouseInfo[HouseID][hWorld] = strval(result);
        cache_get_field_content(0, "Pickup", result), g_HouseInfo[HouseID][hPickup] = strval(result);
        cache_get_field_content(0, "Price", result), g_HouseInfo[HouseID][hPrice] = strval(result);
        cache_get_field_content(0, "Locked", result), g_HouseInfo[HouseID][hLocked] = strval(result);
        cache_get_field_content(0, "StreetName", result), format(g_HouseInfo[HouseID][hStreetName], 64, result);
        cache_get_field_content(0, "LabelID", result), _:g_HouseInfo[HouseID][hLabel] = strval(result);
        HouseID++;
    }
   
    if(g_HouseInfo[HouseID][hOwned] == 0)
    {
        format(string, sizeof(string), "STREET NOT SET\nResidence of The State\nPrice: $%d", g_HouseInfo[HouseID][hPrice]);
        g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1273, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
    }
    if(g_HouseInfo[HouseID][hOwned] == 1)
    {
        format(string, sizeof(string), "%s\nResidence of %s", g_HouseInfo[HouseID][hStreetName], g_HouseInfo[HouseID][hOwner]);
        g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1318, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
    }
    g_HouseInfo[HouseID][hLabel] = CreateDynamic3DTextLabel(string, -1, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
   
    printf("> %d houses have been loaded from the database.", HouseID);
    return 1;
}
Reply
#2

You need to loop through the rows.

pawn Код:
forward OnLoadHouses();
public OnLoadHouses()
{
    new rows, fields, result[129], string[128];
    cache_get_data(rows, fields);

    if(!rows)
    {
        print(!"No houses found!");
        return true;
    }
   
    for(new i = 0; i != rows; i++)
    {
        cache_get_field_content(i, "Owner", result), format(g_HouseInfo[HouseID][hOwner], 24, result);
        cache_get_field_content(i, "OwnerID", result), g_HouseInfo[HouseID][hOwnerid] = strval(result);
        cache_get_field_content(i, "EnPosX", result), g_HouseInfo[HouseID][hEnPosX] = floatstr(result);
        cache_get_field_content(i, "EnPosY", result), g_HouseInfo[HouseID][hEnPosY] = floatstr(result);
        cache_get_field_content(i, "EnPosZ", result), g_HouseInfo[HouseID][hEnPosZ] = floatstr(result);
        cache_get_field_content(i, "ExPosX", result), g_HouseInfo[HouseID][hExPosX] = floatstr(result);
        cache_get_field_content(i, "ExPosY", result), g_HouseInfo[HouseID][hExPosY] = floatstr(result);
        cache_get_field_content(i, "ExPosZ", result), g_HouseInfo[HouseID][hExPosZ] = floatstr(result);
        cache_get_field_content(i, "Interior", result), g_HouseInfo[HouseID][hInterior] = strval(result);
        cache_get_field_content(i, "World", result), g_HouseInfo[HouseID][hWorld] = strval(result);
        cache_get_field_content(i, "Pickup", result), g_HouseInfo[HouseID][hPickup] = strval(result);
        cache_get_field_content(i, "Price", result), g_HouseInfo[HouseID][hPrice] = strval(result);
        cache_get_field_content(i, "Locked", result), g_HouseInfo[HouseID][hLocked] = strval(result);
        cache_get_field_content(i, "StreetName", result), format(g_HouseInfo[HouseID][hStreetName], 64, result);
        cache_get_field_content(i, "LabelID", result), _:g_HouseInfo[HouseID][hLabel] = strval(result);
        HouseID++;
   
        if(g_HouseInfo[HouseID][hOwned] == 0)
        {
            format(string, sizeof(string), "STREET NOT SET\nResidence of The State\nPrice: $%d", g_HouseInfo[HouseID][hPrice]);
            g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1273, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
        }
        if(g_HouseInfo[HouseID][hOwned] == 1)
        {
            format(string, sizeof(string), "%s\nResidence of %s", g_HouseInfo[HouseID][hStreetName], g_HouseInfo[HouseID][hOwner]);
            g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1318, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
        }
        g_HouseInfo[HouseID][hLabel] = CreateDynamic3DTextLabel(string, -1, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
    }

    printf("> %d houses have been loaded from the database.", HouseID);
    return 1;
}
Reply
#3

Well, if I haven't looped it, it would atleast load one house if it's setup correctly, right?

SAVING
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(g_PlayerInfo[playerid][pAdmin] == 6 && g_AdminLogged[playerid] == 1)
    {
        new
            string[128],
            query[300],
            Float:x,
            Float:y,
            Float:z;

        HouseID++;

        format(string, sizeof(string), "STREET NOT SET\nResidence of The State\nPrice: $%d", g_HouseInfo[HouseID][hPrice]);
        GetPlayerPos(playerid, x, y, z);
       
        g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1273, 23, x, y, z, 0, 0, -1, 250);
        g_HouseInfo[HouseID][hLabel] = CreateDynamic3DTextLabel(string, -1, x, y, z, 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
       
        format(string, sizeof(string), "House ID: %d created", HouseID);
        SendClientMessage(playerid, -1, string);
       
        g_HouseInfo[HouseID][hWorld] = HouseID;
       
        format(query, sizeof(query), "INSERT INTO `Houses` (ID, Owner, Owned, OwnerID, EnPosX, EnPosY, EnPosZ, \
                    Interior, World, Pickup, Price, Locked, StreetName, LabelID) \
                    VALUES('%i', 'The State', '0', '499', '%f', '%f', '%f', '0', '%d', '1273', '500000', '1', 'Default', '%d')"
,
                    HouseID, x, y, z, g_HouseInfo[HouseID][hWorld], _:g_HouseInfo[HouseID][hLabel]);
        mysql_function_query(g_Handle, query, false, "SendQuery", "");
       
    } else return SendClientMessage(playerid, -1, "SERVER: You are not authorized to use this command.");
    return 1;
}
Reply
#4

Ah I didn't notice that SELECT query, you don't need to loop then.

How you are getting the ID, I can see it's a stock not a callback, is there any more query ran to get the house ID first? Why not just select all data also limit it? Then looping through the rows.

PHP код:
SELECT FROM `houses
OR with limiting:

PHP код:
SELECT FROM `housesLIMIT 0,max_houses 
Reply
#5

Hm, no I don't seem to have any callback for checking the HouseID's, would you care to help me out?

Found it! It doesn't loop through all the HouseID's it just spawns ID 0 and nothing more..
Reply
#6

Quote:
Originally Posted by Tingesport
Посмотреть сообщение
Hm, no I don't seem to have any callback for checking the HouseID's, would you care to help me out?
Can you show your MySQL table structure? You better use AUTO_INCREMENT instead of manually adding the ID through incrementing the HouseID variable. After that, you just have to use:

PHP код:
INSERT INTO `Houses` (OwnerOwnedOwnerIDEnPosXEnPosYEnPosZInteriorWorldPickupPriceLockedStreetNameLabelIDVALUES('The State''0''499''%f''%f''%f''0''%d''1273''500000''1''Default''%d' 
As you see I've removed the ID because it will increase whenever you will INSERT the data into the Houses table.
Reply
#7

Turned on AUTO_INCREMENT on the ID row.
Reply
#8

Quote:
Originally Posted by Tingesport
Посмотреть сообщение
Turned on AUTO_INCREMENT on the ID row.
Not sure if this would work, but worth giving it a shot.

pawn Код:
stock LoadHouses()
{
    mysql_function_query(g_Handle, "SELECT * FROM `houses`", true, "OnLoadHouses", "");
}

forward OnLoadHouses();
public OnLoadHouses()
{
    new rows, fields, result[129], string[128];
    cache_get_data(rows, fields);

    if(!rows)
    {
        print(!"No houses found!");
        return true;
    }
   
    for(new i = 0; i != rows; i++)
    {
        cache_get_field_content(i, "ID", HouseID);
        cache_get_field_content(i, "Owner", result), format(g_HouseInfo[HouseID][hOwner], 24, result);
        cache_get_field_content(i, "OwnerID", result), g_HouseInfo[HouseID][hOwnerid] = strval(result);
        cache_get_field_content(i, "EnPosX", result), g_HouseInfo[HouseID][hEnPosX] = floatstr(result);
        cache_get_field_content(i, "EnPosY", result), g_HouseInfo[HouseID][hEnPosY] = floatstr(result);
        cache_get_field_content(i, "EnPosZ", result), g_HouseInfo[HouseID][hEnPosZ] = floatstr(result);
        cache_get_field_content(i, "ExPosX", result), g_HouseInfo[HouseID][hExPosX] = floatstr(result);
        cache_get_field_content(i, "ExPosY", result), g_HouseInfo[HouseID][hExPosY] = floatstr(result);
        cache_get_field_content(i, "ExPosZ", result), g_HouseInfo[HouseID][hExPosZ] = floatstr(result);
        cache_get_field_content(i, "Interior", result), g_HouseInfo[HouseID][hInterior] = strval(result);
        cache_get_field_content(i, "World", result), g_HouseInfo[HouseID][hWorld] = strval(result);
        cache_get_field_content(i, "Pickup", result), g_HouseInfo[HouseID][hPickup] = strval(result);
        cache_get_field_content(i, "Price", result), g_HouseInfo[HouseID][hPrice] = strval(result);
        cache_get_field_content(i, "Locked", result), g_HouseInfo[HouseID][hLocked] = strval(result);
        cache_get_field_content(i, "StreetName", result), format(g_HouseInfo[HouseID][hStreetName], 64, result);
        cache_get_field_content(i, "LabelID", result), _:g_HouseInfo[HouseID][hLabel] = strval(result);
   
        if(g_HouseInfo[HouseID][hOwned] == 0)
        {
            format(string, sizeof(string), "STREET NOT SET\nResidence of The State\nPrice: $%d", g_HouseInfo[HouseID][hPrice]);
            g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1273, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
        }
        if(g_HouseInfo[HouseID][hOwned] == 1)
        {
            format(string, sizeof(string), "%s\nResidence of %s", g_HouseInfo[HouseID][hStreetName], g_HouseInfo[HouseID][hOwner]);
            g_HouseInfo[HouseID][hPickup] = CreateDynamicPickup(1318, 23, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 0, 0, -1, 250);
        }
        g_HouseInfo[HouseID][hLabel] = CreateDynamic3DTextLabel(string, -1, g_HouseInfo[HouseID][hEnPosX], g_HouseInfo[HouseID][hEnPosY], g_HouseInfo[HouseID][hEnPosZ], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
    }

    printf("> %d houses have been loaded from the database.", HouseID);
    return 1;
}
Reply
#9

It worked, thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)