SA-MP Forums Archive
top 5 kills in mysql - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: top 5 kills in mysql (/showthread.php?tid=524703)



top 5 kills in mysql - Onfroi - 08.07.2014

Hello, I was trying to make a top5 kills textdraw in mysql but it didn't work. This is what I had:
pawn Код:
stock ShowTopKills()
{
    new names[100],tKills[100],ID;
    mysql_query("SELECT `Username`, `Kills` FROM `Accounts` ORDER BY `Kills` DESC LIMIT 5");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        new username[24],pkills[80];
        ID++;
        mysql_fetch_field_row(username, "Username");
        mysql_fetch_field_row(pkills, "Kills");
        format(names, sizeof(names), "%s%d. i%s~n~~n~~n~", names, ID, username);
        format(tKills, sizeof(tKills), "%d~n~~n~~n~",strval(pkills));
    }
    TextDrawSetString(Top1[0], names);
    TextDrawSetString(Top1[1], tKills);
    mysql_free_result();
    return 1;
}
Although this doesn't work and also it's not really what I want, because I want to set the textdraws with name and kills IF ONLY there are top 5 killers, but if there's not I want the textdraw to say EMPTY and 0 kills. I don't know if I explained correctly but any help would be appreciated.


Re: top 5 kills in mysql - nmader - 08.07.2014

pawn Код:
stock ShowTopKills()
{
    new names[100],tKills[100],ID;
    mysql_query("SELECT `Username`, `Kills` FROM `Accounts` ORDER BY `Kills` DESC LIMIT 5");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        new count = mysql_num_rows();
        while(count != 0)
        {
            new username[24],pkills[80];
            ID++;
            count--;
            mysql_fetch_field_row(username, "Username");
            mysql_fetch_field_row(pkills, "Kills");
            format(names, sizeof(names), "%s%d. i%s~n~~n~~n~", names, ID, username);
            format(tKills, sizeof(tKills), "%d~n~~n~~n~",strval(pkills));
        }
    }
    TextDrawSetString(Top1[0], names);
    TextDrawSetString(Top1[1], tKills);
    mysql_free_result();
    return 1;
}
Untested, I think it would work, but lemme know how it goes.


Re: top 5 kills in mysql - Onfroi - 08.07.2014

Quote:
Originally Posted by nmader
Посмотреть сообщение
pawn Код:
stock ShowTopKills()
{
    new names[100],tKills[100],ID;
    mysql_query("SELECT `Username`, `Kills` FROM `Accounts` ORDER BY `Kills` DESC LIMIT 5");
    mysql_store_result();
    while(mysql_retrieve_row())
    {
        new count = mysql_num_rows();
        while(count != 0)
        {
            new username[24],pkills[80];
            ID++;
            count--;
            mysql_fetch_field_row(username, "Username");
            mysql_fetch_field_row(pkills, "Kills");
            format(names, sizeof(names), "%s%d. i%s~n~~n~~n~", names, ID, username);
            format(tKills, sizeof(tKills), "%d~n~~n~~n~",strval(pkills));
        }
    }
    TextDrawSetString(Top1[0], names);
    TextDrawSetString(Top1[1], tKills);
    mysql_free_result();
    return 1;
}
Untested, I think it would work, but lemme know how it goes.
That crashed the server for some reason.