SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/09/2016, 07:55 PM   #1
Ahmed21
Big Clucker
 
Join Date: Jul 2016
Posts: 158
Reputation: 3
Default MySQL Help

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;

Ahmed21 is offline   Reply With Quote
Old 13/09/2016, 08:40 PM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,066
Reputation: 2660
Default Re: MySQL Help

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.
__________________
Vince is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL Plugin r39-2 Error: Can't connect to local MySQL server through socket Emre__ Scripting Help 10 30/07/2014 08:26 AM
[Tutorial] [VIDEO] MySQL ORM r38: How to pair GM with MySQL & creation of registration/connection system cArnasLT Tutorials 3 19/05/2014 02:08 PM
BlueG MySQL plugin - Failed (plugins/mysql.so: undefined symbol: _Z13stringvprintfPKcPc) linuxthefish Plugin Development 10 13/07/2013 10:56 AM
[Tool/Web/Other] MySQL DB Manager - Easily manage your MySQL databases with this remote application fiki574 Tools and Files 13 22/07/2012 09:41 AM


All times are GMT. The time now is 08:16 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.