SA-MP Forums Archive
[MySQL] Top Online - 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: [MySQL] Top Online (/showthread.php?tid=564564)



[MySQL] Top Online - ReD_HunTeR - 22.02.2015

fixed!


Re: [MySQL] Top Online - Naresh - 22.02.2015

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


Re: [MySQL] Top Online - CalvinC - 22.02.2015

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


Re: [MySQL] Top Online - JeaSon - 22.02.2015

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;
}



Re: [MySQL] Top Online - ReD_HunTeR - 22.02.2015

Fixed!


Re: [MySQL] Top Online - Extremo - 22.02.2015

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.


Re: [MySQL] Top Online - JeaSon - 22.02.2015

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);



Re: [MySQL] Top Online - Vince - 22.02.2015

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.


Re: [MySQL] Top Online - Extremo - 22.02.2015

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.