SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 11/03/2018, 02:53 PM   #1
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 242
Reputation: 15
Default top 10 query mysql

PHP Code:
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.
wallen is offline   Reply With Quote
Old 11/03/2018, 03:07 PM   #2
AdamsLT
Big Clucker
 
AdamsLT's Avatar
 
Join Date: Oct 2011
Location: Lithuania
Posts: 125
Reputation: 33
Default Re: top 10 query mysql

Try moving
PHP Code:
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.
AdamsLT is offline   Reply With Quote
Old 11/03/2018, 03:12 PM   #3
MBJ
Big Clucker
 
Join Date: Jul 2016
Posts: 199
Reputation: 72
Default Re: top 10 query mysql

PHP Code:
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

__________________


MBJ is offline   Reply With Quote
Old 11/03/2018, 04:17 PM   #4
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 858
Default Re: top 10 query mysql

"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.
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 11/03/2018, 05:09 PM   #5
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 242
Reputation: 15
Default Re: top 10 query mysql

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 Code:
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;

wallen is offline   Reply With Quote
Old 11/03/2018, 05:20 PM   #6
alanhutch
Huge Clucker
 
alanhutch's Avatar
 
Join Date: Nov 2010
Location: Florence, Italy. Reputation: 9999
Posts: 363
Reputation: 8
Default Re: top 10 query mysql

I think you have to use strcat function.
alanhutch is offline   Reply With Quote
Old 11/03/2018, 05:28 PM   #7
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 242
Reputation: 15
Default Re: top 10 query mysql

PHP Code:
            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"""); 
Code:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3979) : error 035: argument type mismatch (argument 3)
Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
PHP Code:
            strcat(gString"\n%s{ff99cc}%s {ffffff}(%d) (%d)\n"gStringget_nameget_respectget_kills); 
wallen is offline   Reply With Quote
Old 11/03/2018, 06:03 PM   #8
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 858
Default Re: top 10 query mysql

Since you are concatenating strings in format, you can do this:
PHP Code:
new gString[900] = "Nickname \tPoints \tKills\n"// this is the beginning of your string 
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 11/03/2018, 06:08 PM   #9
AdamsLT
Big Clucker
 
AdamsLT's Avatar
 
Join Date: Oct 2011
Location: Lithuania
Posts: 125
Reputation: 33
Default Re: top 10 query mysql

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 Code:
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

AdamsLT is offline   Reply With Quote
Old 11/03/2018, 06:13 PM   #10
wallen
Huge Clucker
 
wallen's Avatar
 
Join Date: Aug 2015
Location: Italia
Posts: 242
Reputation: 15
Default Re: top 10 query mysql

Thanks works, appreciated
wallen is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[MySQL R39-3] MySQL losing connection during query MEW273 Scripting Help 2 13/04/2015 08:10 AM
MySQL query only updates first letter of column. (BlueG MySQL) Jimmy0wns Scripting Help 1 06/04/2015 12:04 PM
[MYSQL] MySQL Query unsuccesfull toofast Scripting Help 8 04/07/2013 04:19 PM
[Help][MySQL]MySQL query unsuccessful. Timmi Scripting Help 14 01/01/2012 02:01 PM
Failed to exeute query. Lost connection to MySQL server during query. *IsBack Help Archive 10 06/01/2011 08:50 AM


All times are GMT. The time now is 04:01 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.