MYSQL problem
#1

Im trying to get the last 10 logins to show up, 'Player Name' logged in 'date and time'.
It shows me 'Richie© logged in NULL'. Why?

Field 'PlayerName' is varchar 24, 'Time' is varchar 20 in the DB.
pawn Код:
IRCCMD:lastlogins(botid, channel[], user[], host[], params[])
{
    if (IRC_IsOp(botid, channel, user))
    {
        mysql_function_query(gConnectionhandle, "SELECT DISTINCT `PlayerName` FROM `lol_Players` ORDER BY `Time` DESC LIMIT 10", true, "iLast10Logins", "s", channel);
    }
    return 1;
}

forward iLast10Logins(channel[]);
public iLast10Logins(channel[])
{
    new rows, fields, time[20], user[24], string[60];
    cache_get_data(rows, fields);
    IRC_GroupSay(gGroupID, channel, "________ Last 10 Logins ________");
    for(new i=0; i<rows; i++)
    {
        cache_get_field_content(i, "PlayerName", user);
        cache_get_field_content(i, "Time", time);
        format(string, sizeof(string), "%s logged in %s", user, time);
        IRC_GroupSay(gGroupID, channel, string);
    }
    return 1;
}
Reply
#2

You aren't selecting the time column in the query.
Reply
#3

Oh, so i have to;
pawn Код:
SELECT DISTINCT `PlayerName`, `Time` ...
Edit: Yes, i had to! Thanks SuperViper!
i thought it would return entire row, but i was wrong.
Reply
#4

SuperViper's solution did not work as i hoped for.

Select's 10 last players, excluding relogs. But shows Time as NULL.
pawn Код:
SELECT DISTINCT `PlayerName` FROM `lol_Players` ORDER BY `Time` DESC LIMIT 10
Shows Time correctly, but does not exclude 'relogs'.
pawn Код:
SELECT DISTINCT `PlayerName`, `Time` FROM `lol_Players` ORDER BY `Time` DESC LIMIT 10
pawn Код:
[22:26] <SA-TDM[1]> ________ Last 10 Logins ________
[22:26] <SA-TDM[0]> givi.koguashvili logged in 11/06/2013 8:35
[22:26] <SA-TDM[0]> Uros_Andjelkovic logged in 11/06/2013 8:29
[22:26] <SA-TDM[0]> mohamed logged in 11/06/2013 8:27
[22:26] <SA-TDM[0]> BOSS2013 logged in 11/06/2013 8:17
[22:26] <SA-TDM[1]> givi.koguashvili logged in 11/06/2013 8:41 // 3 relogs, i want to exclude it and only show last one.
[22:26] <SA-TDM[1]> givi.koguashvili logged in 11/06/2013 8:32
[22:26] <SA-TDM[1]> givi.koguashvili logged in 11/06/2013 8:28
[22:26] <SA-TDM[1]> Uros_Andjelkovic logged in 11/06/2013 8:27
[22:26] <SA-TDM[1]> Jonh_Henson logged in 11/06/2013 8:12
Reply
#5

bump
Reply
#6

PHP код:
SELECT MAX(PlayerName), MAX(TimeFROM lol_Players GROUP BY PlayerName ORDER BY Time DESC LIMIT 10 
Try that instead. I'm not too good with group by since it tends to complain a lot about aggregate functions. Or at least it did in MSSQL.
Reply
#7

Vince saving the day again
Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)