problem loading stats with mysql
#3

sscanf fails at long data, I personaly use this method.

pawn Код:
LoadPlayer(playerid)
{
    new Data[2048],key[256],idx,Names[24];
    GetPlayerName(playerid,Names,sizeof(Names));
    mysql_real_escape_string(Names,Names);
    mysql_queryF( "SELECT * FROM `users` WHERE `user_name` = '%s'",Names);
    mysql_store_result();
    mysql_fetch_row_format(Data,"|");
    printf("Data lenght: %d",strlen(Data));
    key = strtuk( Data, idx, '|' );
    for(new s = -1; s < 175; s++ )// change 175 to your value count
    {
        switch(s)
        {
            case 0: strmid(Pinfo[playerid][Password], key, 0, strlen(key), 255);
            case 1: Pinfo[playerid][Level] = strval( key );
            case 2: Pinfo[playerid][Admin] = strval( key );
            case 3: Pinfo[playerid][Skin] = strval( key );
            case 4: Pinfo[playerid][Cash] = strval( key );
            case 5: Pinfo[playerid][Local] = strval( key );
        }
        key = strtuk( Data, idx, '|' );
    }
    mysql_free_result();
}
and here is strtuk
pawn Код:
strtuk(const str[], &index, delimiter)
{
    new length = strlen(str);
    while ((index < length) && (str[index] == delimiter))
    {
        index++;
    }

    new offset = index;
    new result[128];
    while ((index < length) && (str[index] != delimiter) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = str[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Just always make sure you keep same order, I mean if you use this, its not recommended to add new values in middle of SQL table, also I started loop with -1, because in my table first value is user name, but why we need to load it.
Reply


Messages In This Thread
problem loading stats with mysql - by b.rock - 12.04.2011, 02:18
Re: problem loading stats with mysql - by Oliverraisk - 12.04.2011, 04:19
Re: problem loading stats with mysql - by Voldemort - 12.04.2011, 07:40
Re: problem loading stats with mysql - by Vince - 12.04.2011, 08:43

Forum Jump:


Users browsing this thread: 2 Guest(s)