top 10 query mysql
#1

PHP код:
CMD:top10(playeridparams[])
{
    new 
gString[900], query[70];
    new 
rows cache_num_rows();
    
    
mysql_format(g_SQLquerysizeof query"SELECT * FROM `players` WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10"true);
    
mysql_tquery(g_SQLquery);
    
    if (
rows)
    {
        for (new 
0rows++)
        {
            
cache_get_value(i"username"pInfo[playerid][Name], MAX_PLAYER_NAME);
            
cache_get_value_int(i"respect"pInfo[playerid][Respect]);
            
format(gStringsizeof(gString), "%s%s (%s)"gStringpInfo[playerid][Name], pInfo[playerid][Respect]);
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"/top10 players"gString"Ok""");
           
format(gStringsizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table."PlayerName[playerid], playerid);
        
SendClientMessageToAll(-1gString);
    }
    
    return 
1;

What's wrong? even the SendClientMessageToAll not showing.
Reply
#2

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.
Reply
#3

PHP код:
CMD:top10(playeridparams[]) 

    new 
gString[900], query[70]; 
     
    
mysql_format(g_SQLquerysizeof query"SELECT * FROM `players` WHERE `respect` > 0 ORDER BY `respect` DESC LIMIT 10"true); 
    new 
Cache:cache mysql_query(g_SQLquery);
    new 
rows cache_num_rows(); 
    
    if (
rows
    { 
        for (new 
0rows++) 
        { 
            
cache_get_value(i"username"pInfo[playerid][Name], MAX_PLAYER_NAME); 
            
cache_get_value_int(i"respect"pInfo[playerid][Respect]); 
            
format(gStringsizeof(gString), "%s%s (%s)"gStringpInfo[playerid][Name], pInfo[playerid][Respect]); 
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"/top10 players"gString"Ok"""); 
        
format(gStringsizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table."PlayerName[playerid], playerid); 
        
SendClientMessageToAll(-1gString); 
    } 
    
cache_delete(cache);
     
    return 
1

Reply
#4

"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.
Reply
#5

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(playeridparams[])
{
    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 
0rows++)
        {
            new 
get_name[MAX_PLAYER_NAME], get_respect 0get_kills 0;
            
cache_get_value(i"username"get_nameMAX_PLAYER_NAME);
            
cache_get_value_int(i"respect"get_respect);
            
cache_get_value_int(i"kills"get_kills);
            
            
format(gStringsizeof(gString), "%s{ff99cc}%s {ffffff}(%d) (%d)\n"gStringget_nameget_respectget_kills);
        }
        
/*ShowPlayerDialog(playerid, DIALOG_TOP, DIALOG_STYLE_LIST, "top 10 lsdm players", gString, "Ok", ""); */
        
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_TABLIST_HEADERS"Top 10 LSDM players""Nickname \tPoints \tKills\n\" "gString", "Ok", "");
        
           format(gString, sizeof(gString), "
{99ff66}(INFO) %( %is viewing /top10 table.", PlayerName[playerid], playerid);
        SendClientMessageToAll(-1, gString);
    }
    return 1;

Reply
#6

I think you have to use strcat function.
Reply
#7

PHP код:
            strcat(gString"{8585C2}Nickname\t{8585C2}Points\t{8585C2}Kills",sizeof(gString));
            
strcat(gString"\n%s{ff99cc}%s {ffffff}(%d) (%d)\n"gStringget_nameget_respectget_kills);
            
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_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"gStringget_nameget_respectget_kills); 
Reply
#8

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 
Reply
#9

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(playeridparams[]) 

    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(gStringsizeof(gString), "{ff99cc}Nickname\t{ffffff}Respect\tKills\n"get_nameget_respectget_kills); 
        for (new 
0rows++) 
        { 
            new 
get_name[MAX_PLAYER_NAME], get_respect 0get_kills 0
            
cache_get_value(i"username"get_nameMAX_PLAYER_NAME); 
            
cache_get_value_int(i"respect"get_respect); 
            
cache_get_value_int(i"kills"get_kills); 
             
            
format(gStringsizeof(gString), "%s{ff99cc}%s\t{ffffff}(%d)\t(%d)\n"gStringget_nameget_respectget_kills); 
        } 
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_TABLIST_HEADERS"Top 10 LSDM players"gString"Ok"""); 
         
        
format(gStringsizeof(gString), "{99ff66}(INFO) %s ( %d ) is viewing /top10 table."PlayerName[playerid], playerid); 
        
SendClientMessageToAll(-1gString); 
    } 
    return 
1

Reply
#10

Thanks works, appreciated
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)