Get rank direct from mysql
#1

Is it possible to get players rank by Score direct from database?

I mean sql function that would return 2 ID rank as #1, 1 ID rank as #2...

example: GetIDrank(2); would return 1;
example1: GetIDrank(0); would return 3;

ID Score
0 5
1 6
2 8
3 1
Reply
#2

Ugly, unthreaded function:
pawn Код:
GetIDRank(id)
{
    new
        query[128],
        value
    ;

    mysql_format(handle, query, sizeof query, "SELECT COUNT(id) AS rank FROM <tablename> WHERE Score >= (SELECT Score FROM <tablename> WHERE id = %d)", id);
    new Cache:result = mysql_query(MySQL, query);
    value = cache_get_row_count(handle) ? cache_get_field_content_int(0, "rank", handle) : -1;
    cache_delete(result);

    return value;
}
Don't call this function often, unthreaded queries are really rarely necessary. Use inline handling if you want to keep your logic together, but still use threaded version
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)