SA-MP Forums Archive
LastLog CMD - 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: LastLog CMD (/showthread.php?tid=661052)



LastLog CMD - MarianImmortalGod - 20.11.2018

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



Re: LastLog CMD - =KempeR= - 20.11.2018

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;




Re: LastLog CMD - MarianImmortalGod - 20.11.2018

Dosen't work


Re: LastLog CMD - =KempeR= - 20.11.2018

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


Re: LastLog CMD - MarianImmortalGod - 22.11.2018

Done, now it works thx

Thx for your help