sscanf saving issue
#1

Hi,
I'm facing a problem when loading data from a mysql db...
I'm trying to save them in an enum, here's the code
pawn Код:
stock Load()
{
    new string[100], tmp[300], rows = 0, n = 1;
    format(string, sizeof(string), "SELECT * FROM `table` ORDER BY `id` ASC");
    mysql_query(string);
    mysql_store_result();
    while(mysql_fetch_row(tmp, "|"))
    {
        rows++;
        print(tmp);
        if(!sscanf(tmp, "p<|>e<is[50]iiii>", MyData[n]))
        {
            n++;
        }
    }
    mysql_free_result();
        Count = n;
    return 1;
}
the enum:
pawn Код:
enum CI
{
    compID,
    compName[55],
    compOwner,
    compKind,
    compBank,
    compActive
}
new MyData[][CI];
here's the string that is printed as "tmp" (only 1 line, as there only is one line in the db)
Код:
1|This Name|1|1|0|1
although the data are saved wrong, if I use this:
pawn Код:
for(new n=1; n<=Count; n++)
    {

        format(string, sizeof(string), "%d", MyData[n][compOwner]);
        SendClientMessage(playerid, COLOR_GREY, string);
        format(string, sizeof(string), "%s", MyData[n][compName]);
SendClientMessage(playerid, COLOR_GREY, string);
    }
it shows 0 as owner whereas it should be 1 and nothing for the name.

where's the mistake on that?
Reply
#2

anyone?
Reply
#3

bump
Reply
#4

another bump again
Reply
#5

I'm going to suggest upgrading your mysql to use threaded queries. It's much easier and less prone to making problems like this, as well as lag-free
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)