Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

MYSQL multiple queries in one command

$
0
0
Hello com,

Gota big problem with my script, i want to make a command that shows every report ticket stored in the database.
So far it works, i can read and show every field content in the dialog:
- report categorie, timestamp, userid (databaseid), id (ticketid)
Now, we wanna display the USERNAME instead of the userid (databaseid), so we need to start a second query selecting the username from the players table (the stock), but after we made our first attemps, it looked like this:

(Ignore that the buttons etc. are in german but the code is english)

The first row is perfectly fine, but then it returns NULL.

Our code:
PHP Code:

cmd:reports(playeridparams[])
{
    if(!
IsAdmin(playerid1))return noaccess
    
new query[128], str[400];
    
mysql_format(dbhandlequerysizeof(query),"SELECT * FROM tickets WHERE status = 0");
    
mysql_query(dbhandlequery);
    
format(str,sizeof(str),"Typ\tUsername\tTimestamp\n");
    new 
rowsfieldsidx;
    
cache_get_data(rowsfieldsdbhandle); //Get rows and fields 
    
if(!rows)return SendClientMessage(playeridGRAU"No reports in database!");
    
    while(
idx<rows)
    {
        
printf("idx %d"idx);
        
format(str,sizeof(str),"%s%d\t%s\t%s\n",str,cache_get_field_content_int(idx"kategorie"dbhandle),mysql_GetUserNameFromTable(cache_get_field_content_int(idx"userid"dbhandle)),date(cache_get_field_content_int(idx"timestamp"dbhandle)));
        
idx++;
    }
    return 
ShowPlayerDialog(playeridDIALOG_REPORTLISTDIALOG_STYLE_TABLIST_HEADERS"Report Tickets"str"Show""Close");
}


stock mysql_GetUserNameFromTable(userid)
{
    new 
uname[MAX_PLAYER_NAME];
    new 
query[256];
    
printf("%d"userid);
    
mysql_format(dbhandlequery256"SELECT * FROM spieler WHERE id = %d"userid);
    
mysql_query(dbhandlequery);
    
cache_get_field_content(0"name"unamedbhandle);
    
printf("%s - %s",unamedate(gettime()));
    return 
uname;



Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>