MySQL Help
#1

Look to the MySQL table picture then to the script then look to the SAMP picture. Only last row in the phpmyadmin table works well, others are foked.



PHP Code:
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
#2

Quote:
Code:
GetNameFromMySQLID(givenid), GetNameFromMySQLID(givenbyid)
This is rather bad in this situation because each call is another roundtrip to the database. You should join the required information in the original query so you don't have to do all the extra work. You need: name of recipient, name of sender, amount and reason.

PHP Code:
SELECT 
    recipient
.name
    
sender.name
    
xplog.amount
    
xplog.reason 
FROM
    xplog
INNER JOIN 
    Player recipient ON xplog
.givenID recipient.ID
INNER JOIN 
    Player sender ON xplog
.givenByID sender.ID
ORDER BY xplog
.ID DESC LIMIT 10 
Something like that should work, assuming that your users table is called 'Player'. You will have all the information you need, in the right order. This makes it much easier to parse the data.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)