problem with cmd /top with mysql
#1

I'm not that pro with using MySQL, but i figured out how to select stuffs on table (that i might selected it somehow wrong)

that's the code, i want to show 10 players showing respects.

PHP код:
CMD:top(playerid)
{
    
mysql_query(connection"SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true);
    new 
gString[256], name[MAX_PLAYER_NAME];
    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 %d Respect\n"gStringnamepInfo[playerid][Respect]);
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"Top Respect"gString"Ok""");
    }
    return 
1;

Errors:

PHP код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3927) : error 017undefined symbol "connection"
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
1 Error

Line 3927:

PHP код:
   mysql_query(connection"SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true); 
Photo of my MySQL table:



Using MySQL plugin R41-2.
Reply
#2

the connection variable is not defined
Reply
#3

Try this if you're using MYSQL R41+

PHP код:
CMD:top(playerid)  

    new 
query[256]; 
    
mysql_format(Databasequerysizeof(query), "SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true);  
    
mysql_tquery(Databasequery);  
    new 
gString[256], name[MAX_PLAYER_NAME];  
    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 %d Respect\n"gStringnamepInfo[playerid][Respect]);  
        }  
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"Top Respect"gString"Ok""");  
    }  
    return 
1;  

Reply
#4

connection should be your SQL var, something like so.

Код:
new MySQLOpt: option_id = mysql_init_options();
mysql_set_option(option_id, AUTO_RECONNECT, true); // it automatically reconnects when loosing connection to mysql server
SQL = mysql_connect(MySQL_HOST, MySQL_USER, MySQL_PASS, MySQL_DB, option_id); // AUTO_RECONNECT is enabled for this connection handle only
Find where you did the MySQL connection, and replace "connection" with your defined var.
Reply
#5

@willbedie: i tried your code, and i get 2 errors on that line.

Line: 3928
PHP код:
    mysql_format(querysizeof(query), "SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true); 
PHP код:
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3928) : error 035argument type mismatch (argument 1)
C:\Users\Wallen\Desktop\LS DM\gamemodes\DBv1.pwn(3928) : error 035argument type mismatch (argument 2)
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase


2 Errors

Reply
#6

Quote:
Originally Posted by willbedie
Посмотреть сообщение
Try this if you're using MYSQL R41+

PHP код:
CMD:top(playerid
{
    new 
query[256];
    
mysql_format(Databasequerysizeof(query), "SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true); 
    
mysql_tquery(Databasequery); 
    new 
gString[256], name[MAX_PLAYER_NAME]; 
    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 %d Respect\n"gStringnamepInfo[playerid][Respect]); 
        } 
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"Top Respect"gString"Ok"""); 
    } 
    return 
1


EDITED, my bad sorry.
Reply
#7

Thanks this fixed all errors, now there's a problem with the dialog. There's something bad that doesn't show me the dialog, even tho i already defined it on top

PHP код:
#define DIALOG_TOP                   ( 19 ) 
PHP код:
CMD:top10(playeridparams[])
{
    new 
query[256];
    
mysql_format(Databasequerysizeof(query), "SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10"true);
    
mysql_tquery(Databasequery);
    new 
gString[256];
    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%i %i Respect\n"gStringpInfo[playerid][Name], pInfo[playerid][Respect]);
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"Top Respect"gString"Ok""");
    }
    return 
1;

Why the command is like dead? it doesn't show anything, no unknown command nothing :/

Maybe a problem on

PHP код:
SELECT * `RESPECTFROM `playersWHERE `RESPECT` > 0 ORDER BY `RESPECTDESC LIMIT 010 
? i don't know
Reply
#8

Код:
SELECT * `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10
Turn it into this:

Код:
SELECT `RESPECT` FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 0, 10
Reply
#9

Thanks ill try once home.
Reply
#10

Na, still problems. The command is dead, nothing shows up.

EDIT:

PHP код:
CMD:top10(playeridparams[])
{
    new 
query[256];
    
mysql_format(Databasequerysizeof(query), "SELECT * FROM `players` WHERE `RESPECT` > 0 ORDER BY `RESPECT` DESC LIMIT 10"true);
    
mysql_tquery(Databasequery);
    new 
gString[256];
    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%i %i Respect\n"gStringpInfo[playerid][Name], pInfo[playerid][Respect]);
        }
        
ShowPlayerDialog(playeridDIALOG_TOPDIALOG_STYLE_LIST"Top Respect"gString"Ok""");
    }
    else
        {
            
SendClientMessage(playerid, -1"No top players were found at this time, retrieve in some hours later");
    }
    return 
1;

even tried with

PHP код:
SELECT FROM `playersWHERE `RESPECT` > 0 ORDER BY `RESPECTDESC LIMIT 10 
But still, since i've made an else here it only shows "No top players were found at this time, retrieve in some hours later", so, maybe its because there are no 10 players registered?, cuz on that database only my name is registered tho.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)