[MySQL] Top Online
#1

fixed!
Reply
#2

is that u must use i% for numbers.. try using it.
Reply
#3

Quote:
Originally Posted by Naresh
Посмотреть сообщение
is that u must use i% for numbers.. try using it.
%d and %i are both integers.
https://sampwiki.blast.hk/wiki/Format
Reply
#4

use cache_get_data(rows, fields);

example
pawn Код:
mysql_tquery(mysql, "SELECT `Hour`, `Min`, `Sec`, `Username` FROM `players` ORDER BY `Hour`, `Min`, `Sec` DESC LIMIT 10", "OnTopOnline", "d", playerid);

forward OnTopOnline(playerid);
public OnTopOnline(playerid)
{
    new full_info[600];
    cache_get_data(rows, fields);
    if(!rows) return SendClientMessage(playerid, -1, "No row found");
    for(new i, j = rows; i < j ; i++)
    {
        new username[MAX_PLAYER_NAME + 1], hour, sec, min2, sub_info[500];
        cache_get_field_content(i, "Username", username);
        hour = cache_get_field_content_int(i, "Hour"l);
        min2 = cache_get_field_content_int(i, "Min");
        sec = cache_get_field_content_int(i, "Sec");
        format(sub_info, sizeof sub_info, "%d. Username: %s, Time: (%d|%d|%d)\n", i, username, hour, min2, sec);
        strcat(full_info, sub_info);
    }
    ShowPlayerDialog(playerid, DIALOG_TOPSTATS, DIALOG_STYLE_MSGBOX, "Top Online", full_info, "Close", "");
    return 1;
}
Reply
#5

Fixed!
Reply
#6

Are you sure you're storing not just their current session but their overall session time in hour minute and second?

Also, I'd suggest(just my own opinion) to remove the "Username" after the number, it just boggles it up.

EDIT: I think I just realized I may have misunderstood you. You need to prioritize your ORDER BY as follows:

pawn Код:
SELECT `Hour`, `Min`, `Sec`, `Username` FROM `players` ORDER BY `Hour` DESC, `Min` DESC, `Sec` DESC LIMIT 10
Not tested but I think that achieves the desired result.
Reply
#7

try this

pawn Код:
mysql_format(mysql,query, sizeof(query), "SELECT `Hour`, `Min`, `Sec`, `Username` FROM `players` ORDER BY `Hour`, `Min`, `Sec` DESC LIMIT 10");
mysql_tquery(mysql, query, "OnTopOnLine", "d", playerid);
Reply
#8

Store their online time in seconds only. Get rid of the hours and minutes. The maximum value the field can store would be 2147483647 seconds, which is about the equivalent of 68 years. That way you only need to store and sort one field and you can easily convert back to hours and minutes.

As for the short term solution, what Extremo posted should work. Each column in the 'order by' clause needs to have the sort order specified, otherwise it will default to ascending order.
Reply
#9

Quote:
Originally Posted by Namer
Посмотреть сообщение
try this

pawn Код:
mysql_format(mysql,query, sizeof(query), "SELECT `Hour`, `Min`, `Sec`, `Username` FROM `players` ORDER BY `Hour`, `Min`, `Sec` DESC LIMIT 10");
mysql_tquery(mysql, query, "OnTopOnLine", "d", playerid);
This.. is exactly what he is doing? It gets executed fine, the order by is just not properly prioritized. Check my post for reference.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)