12.04.2011, 07:40
sscanf fails at long data, I personaly use this method.
and here is strtuk
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.
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();
}
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;
}