14.06.2016, 22:26
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:
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(playerid, params[])
{
if(!IsAdmin(playerid, 1))return noaccess
new query[128], str[400];
mysql_format(dbhandle, query, sizeof(query),"SELECT * FROM tickets WHERE status = 0");
mysql_query(dbhandle, query);
format(str,sizeof(str),"Typ\tUsername\tTimestamp\n");
new rows, fields, idx;
cache_get_data(rows, fields, dbhandle); //Get rows and fields
if(!rows)return SendClientMessage(playerid, GRAU, "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(playerid, DIALOG_REPORTLIST, DIALOG_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(dbhandle, query, 256, "SELECT * FROM spieler WHERE id = %d", userid);
mysql_query(dbhandle, query);
cache_get_field_content(0, "name", uname, dbhandle);
printf("%s - %s",uname, date(gettime()));
return uname;
}