MySQL newest 10
#1

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 

Reply
#2

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

Quote:

SELECT * FROM logs ORDER BY id DESC LIMIT 10

Reply
#3

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;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)