Help SQLite
#1

Hello, I have a question, as I can do so that every top name out of different colors?

PHP Code:
format(query,sizeof(query),"SELECT `NAME` FROM `USERS` ORDER BY (`SCORE` * 1) DESC limit 25");
    
result db_query(ULFDB,query);
    
strcat(str"{FFFFFF}ID\tNick\tScore\n");
    for(new 
a;a<db_num_rows(result);a++)
    {
    
db_get_field(result,0,string,128);
    
format(query,sizeof(query),"SELECT `SCORE` FROM `USERS` WHERE `NAME` = '%s'",string);
    
result2 db_query(ULFDB,query);
    
db_get_field(result2,0,string2,128);
    
format(str2,sizeof(str2),"%d\t%s\t%s\n",a+1,string,string2);
    
strcat(strstr2);
    
db_next_row(result);
    
db_free_result(result2);
    }
    
ShowPlayerDialog(playerid,UNUSEDDIALOG_STYLE_TABLIST_HEADERS,"TOP SCORE - ULF",str,"Aceptar",""); 
Reply
#2

You can select multiply columns in one query. Free the result only once (at the end).

It picks a random color to display the name of a player, if you want to show the entire row (line) then move it at the beginning and remove {FFFFFF} before score. Also make sure "str" is big enough to hold data of 25 players.
Static local would also be better.

PHP Code:
result db_query(ULFDB"SELECT NAME,SCORE FROM USERS ORDER BY SCORE DESC LIMIT 25");
str "{FFFFFF}Position\tNick\tScore\n";
new 
p_name[MAX_PLAYER_NAME], color;
for (new 
arows db_num_rows(result); ba++)
{
    
db_get_field(result0p_namesizeof p_name);
    
color = (random(256) * 16777216) + (random(256) * 65536) + (random(256) * 256) + 255;
    
format(str2sizeof(str2), "%d\t{%06x}%s\t{FFFFFF}%d\n"1color >>> 8p_namedb_get_field_int(result1));
    
strcat(strstr2);
  
    
db_next_row(result);
}
db_free_result(result2);
ShowPlayerDialog(playeridUNUSEDDIALOG_STYLE_TABLIST_HEADERS"TOP SCORE - ULF"str"Aceptar"""); 
Reply
#3

it does not work
PHP Code:
format(query,sizeof(query),"SELECT `NAME` FROM `USERS` ORDER BY (`SCORE` * 1) DESC limit 25");
    
result db_query(ULFDB,query);
    
strcat(str"{FFFFFF}ID\tNick\tScore\n");
    for(new 
a;a<db_num_rows(result);a++)
    {
    
db_get_field(result,0,string,128);
    
format(query,sizeof(query),"SELECT `SCORE` FROM `USERS` WHERE `NAME` = '%s'",string);
    
result2 db_query(ULFDB,query);
    
db_get_field(result2,0,string2,128);
    
color = (random(256) * 16777216) + (random(256) * 65536) + (random(256) * 256) + 255;
    
format(str2,sizeof(str2),"%d\t{%06x}%s\t{FFFFFF}%d\n",a+1,color >>> 8,string,string2);
    
strcat(strstr2);
    
db_next_row(result);
    
db_free_result(result2); 
Reply
#4

And it worked, thanks bro +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)