[HELP]Mysql : Getting the top player.
#1

Hey guys,

Im struggling getting the top player in my database with the highest score and displaying it in my server, can somebody present me with a piece of coding how to fetch the Top Player.

I have tried alot of things but it keeps telling me when i compile my script :

CNRskills.pwn(1921) : error 017: undefined symbol "mysql_retrieve_row"
CNRskills.pwn(1923) : error 017: undefined symbol "mysql_fetch_row"
CNRskills.pwn(1927) : warning 217: loose indentation
CNRskills.pwn(1927) : error 017: undefined symbol "mysql_free_result"
Reply
#2

just order the mysql table by the players score. (DESC: from highest score to the lowest score)
Get the first entry then (as this is the player with the highest score then obviously) and display it the way u want.
A quick example i just made for you:

pawn Код:
if (strcmp("/topplayer", cmdtext, true) == 0)
    {
        new p_top[24],score,string[64],row[36];
        mysql_query("SELECT name, score FROM table ORDER BY score DESC Limit 1");
        mysql_store_result();
        mysql_fetch_row(row);
        sscanf(row, "p<|>s[24]d",p_top,score);
        format(string, sizeof string, "Top Player: %s | Score: %d",p_top,score);
        mysql_free_result();
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX,"Top Player", string, "Close", "");
        return 1;
    }
Note: Its just an example, the mysql functions may differ from plugin to plugin but the logic remains the same


regards, wolf.
Reply
#3

Quote:
Originally Posted by BlackWolf120
Посмотреть сообщение
just order the mysql table by the players score. (DESC: from highest score to the lowest score)
Get the first entry then (as this is the player with the highest score then obviously) and display it the way u want.
A quick example i just made for you:

pawn Код:
if (strcmp("/topplayer", cmdtext, true) == 0)
    {
        new p_top[24],score,string[64],row[36];
        mysql_query("SELECT name, score FROM table ORDER BY score DESC Limit 1");
        mysql_store_result();
        mysql_fetch_row(row);
        sscanf(row, "p<|>s[24]d",p_top,score);
        format(string, sizeof string, "Top Player: %s | Score: %d",p_top,score);
        mysql_free_result();
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX,"Top Player", string, "Close", "");
        return 1;
    }
Note: Its just an example, the mysql functions may differ from plugin to plugin but the logic remains the same


regards, wolf.
going to be a slight problem, because it will still give me a undefined function error. like mysql_free_result and mysql_fetch_row wont work
Reply
#4

It would be nice if you could send me a download link of an include file that has these functions
Reply
#5

like i said its just an example to show you a simple idea on how to accomplish what you would like to have.
Im using StrickenKids mysql plugin, you propably the newer one by BlueG.
Just adjust the function names, the queries should all stay the same.
Reply
#6

like i said its just an example to show you a simple idea on how to accomplish what you would like to have.
Im using StrickenKids mysql plugin, you propably the newer one by BlueG.
Just adjust the function names, the queries should all stay the same.
Reply
#7

pawn Код:
stock quickSort(array[], index[], tempvar, tempsize, desc)
{
     new pivot, temp, var, i;
     if(tempvar < tempsize)
     {
        pivot = tempvar;
        var = array[pivot];
        for(i = tempvar + 1; i <= tempsize; i ++)
        {
            if(desc ? (array[i] > var) : (array[i] < var))
            {
                pivot ++;
                temp = array[i];
                array[i] = array[pivot];
                array[pivot] = temp;
                temp = index[i];
                index[i] = index[pivot];
                index[pivot] = temp;
            }
        }
        temp = array[tempvar];
        array[tempvar] = array[pivot];
        array[pivot] = temp;
        temp = index[tempvar];
        index[tempvar] = index[pivot];
        index[pivot] = temp;
        quickSort(array, index, tempvar, pivot - 1, desc);
        quickSort(array, index, pivot + 1, tempsize, desc);
     }
}
Example of usage:
pawn Код:
quickSort(aScoreInfo[eScoreInfo], aScoreInfo[score], 0, countex, true);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)