Help SQLite - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help SQLite (
/showthread.php?tid=618262)
Help SQLite -
BrianFaria - 03.10.2016
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(str, str2);
db_next_row(result);
db_free_result(result2);
}
ShowPlayerDialog(playerid,UNUSED, DIALOG_STYLE_TABLIST_HEADERS,"TOP SCORE - ULF",str,"Aceptar","");
Re: Help SQLite -
Konstantinos - 03.10.2016
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 a, rows = db_num_rows(result); a < b; a++)
{
db_get_field(result, 0, p_name, sizeof p_name);
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, p_name, db_get_field_int(result, 1));
strcat(str, str2);
db_next_row(result);
}
db_free_result(result2);
ShowPlayerDialog(playerid, UNUSED, DIALOG_STYLE_TABLIST_HEADERS, "TOP SCORE - ULF", str, "Aceptar", "");
Re: Help SQLite -
BrianFaria - 03.10.2016
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(str, str2);
db_next_row(result);
db_free_result(result2);
Re: Help SQLite -
BrianFaria - 03.10.2016
And it worked, thanks bro +rep