SA-MP Forums Archive
MySQL newest 10 - 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 newest 10 (/showthread.php?tid=616962)



MySQL newest 10 - Ahmed21 - 13.09.2016

Hello, I have a table, it is a log table, (used to see some logs in the server), anyway, I've made a command in-game to view the newest 10 inserted rows into this table, how will the "for" function be?

Can it be like this?

PHP код:
cache_get_row_count();
    new 
count cache_get_row_count();
    for(new 
count-1count-11i--)
    {
        
SCM(i, -1"hi");
    }
    return 




Re: MySQL newest 10 - Misiur - 13.09.2016

Why won't you just use ORDER BY in your query?

Quote:

SELECT * FROM logs ORDER BY id DESC LIMIT 10




Re: MySQL newest 10 - Ahmed21 - 13.09.2016

Look to the MySQL table picture then to the script then look to the SAMP picture.



PHP код:
CMD:xplog(playeridparams[])
{
    if(!
IsAdminLevel(playerid4)) return NoPermsMSG(playerid);
    
    new 
query[200], dialogfinal[1000], string[128], amountreason[30], givenidgivenbyid;
    
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `xplog` ORDER BY `ID` DESC LIMIT 10");
    new 
Cacheresult mysql_query(mysqlquery);
    
strcat(dialogfinal"Player\tGiven By\tAmount\tReason\n");
    
cache_get_row_count();
    new 
count cache_get_row_count();
    if(
count == 0) return ErrorMSG(playerid"The XP log is empty.");
    for(new 
0counti++)
    {
        
cache_get_row(i3reason);
        
givenid cache_get_field_content_int(i"GivenID");
        
givenbyid cache_get_field_content_int(i"GivenByID");
        
amount cache_get_field_content_int(i"Amount");
        
format(stringsizeof(string), "%s\t%s\t%d\t%s\n"GetNameFromMySQLID(givenid), GetNameFromMySQLID(givenbyid), amountreason);
        
strcat(dialogfinalstring);
    }
    
cache_delete(result);
    
ShowPlayerDialog(playeridDIALOG_XPLOGDIALOG_STYLE_TABLIST_HEADERS""COL_WHITE"XP Log"dialogfinal"Close""");
    return 
1;