Top Killers [MYSQL] Help
#1

Solved.
Reply
#2

Use threaded queries, please.

pawn Код:
new query[128];
new page = 0;
mysql_format(dbhandle, query, "SELECT t0.user, t0.Kills FROM `playerinfo` t0 ORDER BY t0.Kills DESC LIMIT %d, 100", 20*page);
Make sure that page is always positive.
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Use threaded queries, please.

pawn Код:
new query[128];
new page = 0;
mysql_format(dbhandle, query, "SELECT t0.user, t0.Kills FROM `playerinfo` t0 ORDER BY t0.Kills DESC LIMIT %d, 100", 20*page);
Make sure that page is always positive.
Sorry i don't have much knowledge of threaded queries and thou i am not using it.I am using R5 can you please post the code according to it.

Thanks for helping.
Reply
#4

pawn Код:
new query[90];
new page = 0;
if(page < 0) page = -page;
format(query, sizeof query, "SELECT t0.user, t0.Kills FROM `playerinfo` t0 ORDER BY t0.Kills DESC LIMIT %d, 100", 20*page);
You have to retrieve the page variable yourself

#e:

Ok, some more explanation

pawn Код:
#define MaxPages (10)
#define DIALOG_TOPKILLS (1000)
//(...)
CMD:top(pid, params[]) {
    BuildTop(0);
    return 1;
}
//(...)
stock BuildTop(page) {
    new query[96], msg[512];
    if(page < 0) page = -page;
    if(page > MaxPages) page = MaxPages;
    format(query, sizeof query, "SELECT t0.user, t0.Kills FROM `playerinfo` t0 ORDER BY t0.Kills DESC LIMIT %d, 100", 20*page);
    //Process the query, and load variables into msg
    ShowPlayerDialog(pid, DIALOG_TOPKILLS + page, DIALOG_STYLE_MSGBOX, "Top killers", msg, "Next", "Close");
    return 1;
}
//(...)
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    if(response && dialogid >= DIALOG_TOPKILLS && dialogid < DIALOG_TOPKILLS + MaxPages) {
        BuildTop(dialogid - DIALOG_TOPKILLS + 1);
    }  
    return 1;
}
Reply
#5

Thanks for da help!
Reply
#6

Just a quick question: Why bother using the #pragma unused code on 'help'? The code won't show a warning if you don't use it, so telling the compiler you didn't use it is just a waste of code.
Reply
#7

Note: Not tested
pawn Код:
CMD:top20(playerid, params[])
{
    new
        iUser[23],
        iKills[12],
        iStr[521],
        idx
    ;
   
    mysql_query("SELECT `user`, `Kills` FROM `playerinfo` ORDER BY `Kills` DESC LIMIT 20");
    mysql_store_result();
   
    if (mysql_num_rows() != 0)
    {
        while (mysql_retrive_row())
        {
            mysql_fetch_field_row(iUser, "user");
            mysql_fetch_field_row(iKills, "Kills");
            format(iStr, sizeof(iStr), "%s%i) %s with %i kills.\n", iStr, idx, iUser, iKills);
            idx ++;
        }  
        ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Top 20 kills", iStr, "OK", "Cancel");
    }
   
    mysql_free_result();
    return 1;
}
Reply
#8

Quote:
Originally Posted by Mr_DjolE
Посмотреть сообщение
Note: Not tested
pawn Код:
CMD:top20(playerid, params[])
{
    new
        iUser[23],
        iKills[12],
        iStr[521],
        idx
    ;
   
    mysql_query("SELECT `user`, `Kills` FROM `playerinfo` ORDER BY `Kills` DESC LIMIT 20");
    mysql_store_result();
   
    if (mysql_num_rows() != 0)
    {
        while (mysql_retrive_row())
        {
            mysql_fetch_field_row(iUser, "user");
            mysql_fetch_field_row(iKills, "Kills");
            format(iStr, sizeof(iStr), "%s%i) %s with %i kills.\n", iStr, idx, iUser, iKills);
            idx ++;
        }  
        ShowPlayerDialog(playerid, 123, DIALOG_STYLE_LIST, "Top 20 kills", iStr, "OK", "Cancel");
    }
   
    mysql_free_result();
    return 1;
}
Thanks alot dude it worked and i found that in my problem was i was using %d for kills and when i used %s it worked fine but still i am confused as %d should work for it as %s is for strings.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)