[MySQL]Reports command error
#1

Problem : It doesn't show the dialog nor the error.

Command:
pawn Код:
CMD:reports(playerid,params[])
{
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        mysql_function_query(cHandle,"SELECT * FROM `reports` ORDER BY `RDate` DESC LIMIT 5", true, "DisplayReports", "d", "playerid");
    }
    else return NotAllowed(playerid);
    return 1;
}
DisplayReports
pawn Код:
public DisplayReports(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, cHandle);
    if(rows)
    {
        new string[1000], reason[50], reporter[MAX_PLAYER_NAME], reportedplayer[MAX_PLAYER_NAME];
        for(new i =0; i < rows; i++)
        {
            //new mHolder[128];
            cache_get_field_content(i, "Reporter", reporter);
            cache_get_field_content(i, "Name", reportedplayer);
            cache_get_field_content(i, "Reason", reason);
            format(string,sizeof(string),"%s\n%s reported by %s. Reason: %s",string,reportedplayer,reporter,reason);
            ShowPlayerDialog(playerid, DIALOG_REPORTS, DIALOG_STYLE_MSGBOX, "Today's Last 5 reports",string,"Okay","");
        }
    }
    else return SendClientMessage(playerid, -1, ""RED"[REPORTS] "WHITE"There are no reports to be shown.");
    return 1;
}
Reply
#2

You have "playerid" used as a literal string as opposed to the playerid variable. Use:

pawn Код:
CMD:reports(playerid,params[])
{
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        mysql_function_query(cHandle,"SELECT * FROM `reports` ORDER BY `RDate` DESC LIMIT 5", true, "DisplayReports", "d", playerid);
    }
    else return NotAllowed(playerid);
    return 1;
}
Your code would end up opening a dialog on every iteration, so use:

pawn Код:
public DisplayReports(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, cHandle);
    if(rows)
    {
        new string[1000], reason[50], reporter[MAX_PLAYER_NAME], reportedplayer[MAX_PLAYER_NAME];
        for(new i =0; i < rows; i++)
        {
            //new mHolder[128];
            cache_get_field_content(i, "Reporter", reporter);
            cache_get_field_content(i, "Name", reportedplayer);
            cache_get_field_content(i, "Reason", reason);
            format(string,sizeof(string),"%s\n%s reported by %s. Reason: %s",string,reportedplayer,reporter,reason);
        }
        ShowPlayerDialog(playerid, DIALOG_REPORTS, DIALOG_STYLE_MSGBOX, "Today's Last 5 reports",string,"Okay","");
    }
    else return SendClientMessage(playerid, -1, ""RED"[REPORTS] "WHITE"There are no reports to be shown.");
    return 1;
}
Reply
#3

I fixed it like this
pawn Код:
CMD:reports(playerid,params[])
{
    if(PlayerInfo[playerid][Admin] >= 1)
    {
        new Query[100];
        format(Query,sizeof(Query),"SELECT * FROM `reports` ORDER BY `ID` DESC LIMIT 5");
        mysql_function_query(cHandle, Query, true, "DisplayReports", "d", playerid);
    }
    else return NotAllowed(playerid);
    return 1;
}
pawn Код:
public DisplayReports(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, cHandle);
    if(rows)
    {
        new string[1000], reason[50], reporter[MAX_PLAYER_NAME], reportedplayer[MAX_PLAYER_NAME];
        for(new i = 0; i < rows; i++)
        {
            //new mHolder[128];
            cache_get_field_content(i, "Reporter", reporter, cHandle);
            cache_get_field_content(i, "Name", reportedplayer, cHandle);
            cache_get_field_content(i, "Reason", reason, cHandle);
            format(string,sizeof(string),"%s\n"RED"Reporter: "WHITE"%s "RED"Suspect: "WHITE"%s "RED"Reason: "WHITE"%s",string,reportedplayer,reporter,reason);
            ShowPlayerDialog(playerid, DIALOG_REPORTS, DIALOG_STYLE_MSGBOX, "Today's Last 5 reports",string,"Okay","");
        }
    }
    else return SendClientMessage(playerid, -1, ""RED"[REPORTS] "WHITE"There are no reports to be shown.");
    return 1;
}
Thanks tho
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)