MYSQL loading problem
#8

pawn Код:
forward LoadFactions();
public LoadFactions()
{
    new
        Query[300],
        string[128],
        FactionCount;

    mysql_query("SELECT * FROM Factions");
    mysql_store_result();

    new i = 0;
    while(mysql_fetch_row_format(Query, "|"))
    {
        sscanf(Query, "e<p<|>is[128]s[128]dfff>", FInfo[i]);
        format(string,sizeof(string),"Faction Name: %s \nOwned by: %s\nFaction Value: %d", FInfo[i][Name], FInfo[i][Owner], FInfo[i][Value]);

        CreateDynamicPickup(1239, 1, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], -1, -1, -1, 100.0);
        CreateDynamic3DTextLabel(string, COLOR_RED, FInfo[i][LocationX], FInfo[i][LocationY], FInfo[i][LocationZ], 100.0);

        FactionCount++;
        i++;
    }

    mysql_free_result();
    return FactionCount;
}
pawn Код:
forward SaveFactions();
public SaveFactions()
{
    new query[1024];
    for(new i = 0; i < FactionCount; i++)
    {
        format(query, sizeof(query), "UPDATE Factions SET \
                Name = '%s',\
                Owner = '%s',\
                Value = '%d',\
                LocationX = '%f',\
                LocationY = '%f',\
                LocationZ = '%f'\
                WHERE FactionID = '%i'"
,
            FInfo[i][Name],
            FInfo[i][Owner],
            FInfo[i][Value],
            FInfo[i][LocationX],
            FInfo[i][LocationY],
            FInfo[i][LocationZ],
            FInfo[i][FactionID]);
        mysql_query(query);
    }
}
But saving in a loop like that is not recommended. You should save each faction separately when something is changed

pawn Код:
forward SaveFaction(i);
public SaveFaction(i)
{
    new query[1024];
    format(query, sizeof(query), "UPDATE Factions SET \
            Name = '%s',\
            Owner = '%s',\
            Value = '%d',\
            LocationX = '%f',\
            LocationY = '%f',\
            LocationZ = '%f'\
            WHERE FactionID = '%i'"
,
        FInfo[i][Name],
        FInfo[i][Owner],
        FInfo[i][Value],
        FInfo[i][LocationX],
        FInfo[i][LocationY],
        FInfo[i][LocationZ],
        FInfo[i][FactionID]);
    mysql_query(query);
}
Reply


Messages In This Thread
MYSQL loading problem - by Jstylezzz - 26.06.2012, 17:09
Re: MYSQL loading problem - by Vince - 27.06.2012, 10:49
Re: MYSQL loading problem - by Jstylezzz - 27.06.2012, 10:51
Re: MYSQL loading problem - by AndreT - 27.06.2012, 13:29
Re: MYSQL loading problem - by Jstylezzz - 27.06.2012, 13:54
Re: MYSQL loading problem - by Jstylezzz - 28.06.2012, 19:04
Re: MYSQL loading problem - by Jstylezzz - 01.07.2012, 15:30
Re: MYSQL loading problem - by MadeMan - 01.07.2012, 15:47
Re: MYSQL loading problem - by Jstylezzz - 01.07.2012, 15:57
Re: MYSQL loading problem - by Jstylezzz - 03.07.2012, 08:40

Forum Jump:


Users browsing this thread: 1 Guest(s)