Top kills
#1

PHP код:
CMD:top(playeridparams[])
{
    if(
LoggedIn[playerid] == false) return SendClientMessage(playeridCOLOR_RED"ERROR: You must be logged in.");
    
mysql_query(MySQL"SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    
mysql_store_result();
    new 
string[128], pName[24], pKills[5], query[256];
    if(
mysql_num_rows() != 0)
    {
        while(
mysql_fetch_row_format(query"|"))
        {
            
mysql_fetch_field_row(pName"User");
            
mysql_fetch_field_row(pKills"Kills");
            
format(stringsizeof(string), "User: %s. Kills: %i"pNamepKills);
            
SendClientMessage(playeridCOLOR_REDstring);
        }
    }
    
mysql_free_result();
    return 
1;

Kills doesn't return correct number.. it is different every time but not correct.. what am I doing wrong?
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=282052
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
PHP код:
CMD:top(playeridparams[])
{
    if(
LoggedIn[playerid] == false) return SendClientMessage(playeridCOLOR_RED"ERROR: You must be logged in.");
    
mysql_query(MySQL"SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    
mysql_store_result();
    new 
string[128], pName[24], pKills[5];
    if(
mysql_num_rows() != 0)
    {
        while(
mysql_retrieve_row())
        {
            
mysql_fetch_field_row(pName"User");
            
mysql_fetch_field_row(pKills"Kills");
            
format(stringsizeof(string), "User: %s. Kills: %i"pNamepKills);
            
SendClientMessage(playeridCOLOR_REDstring);
        }
    }
    
mysql_free_result();
    return 
1;

I changed my code like that but the result is same..? Thanks for the reply
Reply
#4

Write always which version of mysql because this is weird mysql_query(MySQL,
Reply
#5

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Write always which version of mysql because this is weird mysql_query(MySQL,
MySQL R33
Reply
#6

Try with cache

pawn Код:
CMD:top(playerid, params[])
{
    if(LoggedIn[playerid] == false) return SendClientMessage(playerid, COLOR_RED, "ERROR: You must be logged in.");

    new Cache:result = mysql_query(MySQL, "SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    if((params[0] = cache_num_rows()))
    {
        new pName[24], pKills, string[128];
        for(new i = 0; i < params[0]; i++)
        {
            cache_get_row(i, 0, pName);
            pKills = cache_get_row_int(i, 1);
            format(string, sizeof(string), "User: %s. Kills: %i", pName, pKills);
            SendClientMessage(playerid, COLOR_RED, string);
        }
    }
    cache_delete(result);
    return 1;
}
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Try with cache

pawn Код:
CMD:top(playerid, params[])
{
    if(LoggedIn[playerid] == false) return SendClientMessage(playerid, COLOR_RED, "ERROR: You must be logged in.");

    new Cache:result = mysql_query(MySQL, "SELECT `User`, `Kills` FROM `UserData` ORDER BY `Kills` DESC LIMIT 5");
    if((params[0] = cache_num_rows()))
    {
        new pName[24], pKills, string[128];
        for(new i = 0; i < params[0]; i++)
        {
            cache_get_row(i, 0, pName);
            pKills = cache_get_row_int(i, 1);
            format(string, sizeof(string), "User: %s. Kills: %i", pName, pKills);
            SendClientMessage(playerid, COLOR_RED, string);
        }
    }
    cache_delete(result);
    return 1;
}
Working. Thanks a lot!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)