LastLog CMD
#1

Hey guys, i have a test cmd that gave me info about how many players haven't login in the past 30 days.

The problem is, it shows only if the data in database is stored as year/month/days instead of days/month/year.

Any idea why ? here's the cmd.

UPDATE: The structure 'LastLog' in database is formed as VARCHAR

Код HTML:
CMD:lastlog(playerid)
{
	new string[90], dialog[90], i, iResult[90], query[90];
	gQuery[0] = EOS;
	mysql_format(SQL, string, sizeof(string),  "SELECT * FROM `users` WHERE `LastLog` + INTERVAL 30 DAY <= NOW() ORDER BY `ID` DESC LIMIT 20");
	new Cache:r = mysql_query(SQL, string);
	strcat(dialog, "ID\tLastLog\n");
   	while(i < cache_num_rows())
	{
		cache_get_field_content(i, "LastLog", iResult); format(query, 32, iResult);
		format(string, sizeof(string), "%d\t%s\n", i+1, query);
		strcat(dialog, string);
		i++;
	}
	cache_delete®;
	ShowPlayerDialog(playerid, 123, DIALOG_STYLE_TABLIST_HEADERS, "LastLog", dialog, "Select", "Close");
	return 1;
}
Reply
#2

At first. The best idea is to store date in temporal types such as DATE, DATETIME, TIMESTAMP.
Secondly. Applying functions to table fields is undesirable in any DBMS.
And further. Avoid using mysql_query. Better use threaded mysql queries - mysql_tquery
The use of SQL functions on field can not be avoided here, so the working code should look like this:

PHP код:
CMD:lastlog(playerid)
{
    
mysql_tquery(
        
SQL,
        
"SELECT * FROM `users` WHERE str_to_date(`LastLog`, '%%d/%%m/%%Y') <= NOW() - INTERVAL 30 DAY ORDER BY `ID` DESC LIMIT 20",
        
"lastLogResponse""d"playerid
    
);
    return 
1;
}
forward lastLogResponse(playerid);
public 
lastLogResponse(playerid)
{
    new 
szResult[32], szDialog[652] = "ID\tLastLog"// IDK how long is data that u retrieve from database;
       
for (new 0rowCount cache_num_rows(); rowCounti++)
    {
        
cache_get_field_content(i"LastLog"szResult);
        
format(stringsizeof(string), "%s\n%d\t%s"1szDialogszResult);
    }
    
ShowPlayerDialog(playerid123DIALOG_STYLE_TABLIST_HEADERS"LastLog"szDialog"Select""Close");
    return 
1;

Reply
#3

Dosen't work
Reply
#4

Quote:
Originally Posted by MarianImmortalGod
Посмотреть сообщение
Dosen't work
Please provide us with your database structure and example of storable data.
Reply
#5

Done, now it works thx

Thx for your help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)