Top players(MySQL)
#1

I know that this code gets the top 10 players,But how shall I put them in a message dialog?

PHP код:
SELECT *  FROM `usersORDER BY `ScoreDESC LIMIT 10 
Reply
#2

pawn Код:
stock LoadTop10()
{
    new Query[128];
    mysql_format(mysql, Query, sizeof(Query), "SELECT * FROM `players` ORDER BY `score` DESC LIMIT 10 "); //not tested, might need to fix the query
    mysql_function_query(mysql, Query, false, "LoadScores", "", ""); //init the load scores function with no cache
    return 1; // returning the function true
}


public LoadScores()
{
    new rows, fields;
    cache_get_data(rows, fields, mysql); //returning all 10 players & all their rows/fields
    if(rows)//if there are rows to be retrived continue
    {
        for(new i = 0; i < rows; i++) //loop through all the found rows and pull the following
        {
            new dest[24], score;
            cache_get_row(i, "pName", dest); //get all the player names pulled from the query
            score = cache_get_row_int(i, "score"); //pull all the scores from the rows retrived
            printf("top 10 players are %s wtih scores of %d", dest, scores); //print the result when ever LoadScores is called.
        }
        else
        {
            printf("There are no players saved with score.."); //if there were no rows found in the query called in LoadTop10
            //escape ect..
    }
    return 1;
}
Not tested or anything but you should get the basic idea.
(also idk why the formatting fucked up but w/e.
Reply
#3

Something important to remember is that all you want to select is the player's name and the score so you don't need all (*) the data in the query.

Another thing is to avoid declaring variables inside loops.
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Something important to remember is that all you want to select is the player's name and the score so you don't need all (*) the data in the query.

Another thing is to avoid declaring variables inside loops.
Tell me the idea of doing it,cause the only thing I know is that

PHP код:
SELECT *  FROM `usersORDER BY `ScoreDESC LIMIT 10 
Reply
#5

Replacing * with the column(s) you want to select. An example (change "Username" to the name you have in your table):
pawn Код:
"SELECT Username,Score FROM users ORDER BY Score DESC LIMIT 10"
Read those for more:
http://www.w3schools.com/sql/sql_select.asp
https://sampforum.blast.hk/showthread.php?tid=609261
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)