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(playerid, params[])
{
    if(!
IsAdminLevel(playerid, 4)) return NoPermsMSG(playerid);
    
    new 
query[200], dialogfinal[1000], string[128], amount, reason[30], givenid, givenbyid;
    
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `xplog` ORDER BY `ID` DESC LIMIT 10");
    new 
Cache: result = mysql_query(mysql, query);
    
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 
i = 0; i < count; i++)
    {
        
cache_get_row(i, 3, reason);
        
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(string, sizeof(string), "%s\t%s\t%d\t%s\n", GetNameFromMySQLID(givenid), GetNameFromMySQLID(givenbyid), amount, reason);
        
strcat(dialogfinal, string);
    }
    
cache_delete(result);
    
ShowPlayerDialog(playerid, DIALOG_XPLOG, DIALOG_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: