top 10 query mysql -
wallen - 11.03.2018
PHP код:
CMD:top10(playerid, params[])
{
new gString[900], query[70];
new rows = cache_num_rows();
mysql_format(g_SQL, query, sizeof query, "SELECT * FROM `players` WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10", true);
mysql_tquery(g_SQL, query);
if (rows)
{
for (new i = 0; i < rows; i ++)
{
cache_get_value(i, "username", pInfo[playerid][Name], MAX_PLAYER_NAME);
cache_get_value_int(i, "respect", pInfo[playerid][Respect]);
format(gString, sizeof(gString), "%s%s (%s)", gString, pInfo[playerid][Name], pInfo[playerid][Respect]);
}
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_LIST, "/top10 players", gString, "Ok", "");
format(gString, sizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table.", PlayerName[playerid], playerid);
SendClientMessageToAll(-1, gString);
}
return 1;
}
What's wrong? even the
SendClientMessageToAll not showing.
Re: top 10 query mysql -
AdamsLT - 11.03.2018
Try moving
PHP код:
new rows = cache_num_rows();
below mysql_tquery(g_SQL, query); because you're now getting the number of rows before actually getting the rows.
Re: top 10 query mysql -
MBJ - 11.03.2018
PHP код:
CMD:top10(playerid, params[])
{
new gString[900], query[70];
mysql_format(g_SQL, query, sizeof query, "SELECT * FROM `players` WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10", true);
new Cache:cache = mysql_query(g_SQL, query);
new rows = cache_num_rows();
if (rows)
{
for (new i = 0; i < rows; i ++)
{
cache_get_value(i, "username", pInfo[playerid][Name], MAX_PLAYER_NAME);
cache_get_value_int(i, "respect", pInfo[playerid][Respect]);
format(gString, sizeof(gString), "%s%s (%s)", gString, pInfo[playerid][Name], pInfo[playerid][Respect]);
}
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_LIST, "/top10 players", gString, "Ok", "");
format(gString, sizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table.", PlayerName[playerid], playerid);
SendClientMessageToAll(-1, gString);
}
cache_delete(cache);
return 1;
}
Re: top 10 query mysql -
Gammix - 11.03.2018
"respect" is an integer type but you have it formated with a string specifier (%s), in your format line.
Also there is no use of "\n", so your string will be one line basically.
Re: top 10 query mysql -
wallen - 11.03.2018
Well i just figured out and redit the code myself, now i got a little issue, how do i show it under the dialog id "DIALOG_STYLE_TABLIST_HEADERS" so it will be kind of organized
PHP код:
CMD:top10(playerid, params[])
{
new gString[900];
mysql_query(g_SQL, "SELECT * FROM players WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10");
new rows = cache_num_rows();
if (rows)
{
for (new i = 0; i < rows; i ++)
{
new get_name[MAX_PLAYER_NAME], get_respect = 0, get_kills = 0;
cache_get_value(i, "username", get_name, MAX_PLAYER_NAME);
cache_get_value_int(i, "respect", get_respect);
cache_get_value_int(i, "kills", get_kills);
format(gString, sizeof(gString), "%s{ff99cc}%s {ffffff}(%d) (%d)\n", gString, get_name, get_respect, get_kills);
}
/*ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_LIST, "top 10 lsdm players", gString, "Ok", ""); */
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_TABLIST_HEADERS, "Top 10 LSDM players", "Nickname \tPoints \tKills\n\" "gString", "Ok", "");
format(gString, sizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table.", PlayerName[playerid], playerid);
SendClientMessageToAll(-1, gString);
}
return 1;
}
Re: top 10 query mysql -
alanhutch - 11.03.2018
I think you have to use strcat function.
Re: top 10 query mysql -
wallen - 11.03.2018
PHP код:
strcat(gString, "{8585C2}Nickname\t{8585C2}Points\t{8585C2}Kills",sizeof(gString));
strcat(gString, "\n%s{ff99cc}%s {ffffff}(%d) (%d)\n", gString, get_name, get_respect, get_kills);
}
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_TABLIST_HEADERS, "{0080FF}Top 10 LS:DM players", gString, "Ok", "");
Код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3979) : error 035: argument type mismatch (argument 3)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
PHP код:
strcat(gString, "\n%s{ff99cc}%s {ffffff}(%d) (%d)\n", gString, get_name, get_respect, get_kills);
Re: top 10 query mysql -
Gammix - 11.03.2018
Since you are concatenating strings in format, you can do this:
PHP код:
new gString[900] = "Nickname \tPoints \tKills\n"; // this is the beginning of your string
Re: top 10 query mysql -
AdamsLT - 11.03.2018
I don't believe you can format in the strcat function.
You can continue using format in your case. The first line needs to be the header line, separate the headers with \t, add \n at the end of the line, pass the string to the dialog and you're good.
I think this should work for you. I added the formatting for the first line and then just added tabs to your string.
PHP код:
CMD:top10(playerid, params[])
{
new gString[900];
mysql_query(g_SQL, "SELECT * FROM players WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10");
new rows = cache_num_rows();
if (rows)
{
format(gString, sizeof(gString), "{ff99cc}Nickname\t{ffffff}Respect\tKills\n", get_name, get_respect, get_kills);
for (new i = 0; i < rows; i ++)
{
new get_name[MAX_PLAYER_NAME], get_respect = 0, get_kills = 0;
cache_get_value(i, "username", get_name, MAX_PLAYER_NAME);
cache_get_value_int(i, "respect", get_respect);
cache_get_value_int(i, "kills", get_kills);
format(gString, sizeof(gString), "%s{ff99cc}%s\t{ffffff}(%d)\t(%d)\n", gString, get_name, get_respect, get_kills);
}
ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_TABLIST_HEADERS, "Top 10 LSDM players", gString, "Ok", "");
format(gString, sizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table.", PlayerName[playerid], playerid);
SendClientMessageToAll(-1, gString);
}
return 1;
}
Re: top 10 query mysql -
wallen - 11.03.2018
Thanks works, appreciated