Display results from DB into a dialog
#8

pawn Код:
CMD:reports(playerid, params[])
{
    if(pStats[playerid][pAdmin] < 1) return 1;
    new szQuery[96], iStart = 0, iEnd = 15;
    format(szQuery, sizeof(szQuery), "SELECT `reportID`, `reportedUsername`, `reportReason` FROM `reportsLog` LIMIT %d, %d", iStart, iEnd);
    mysql_function_query(1, szQuery, true, "thread_LoadReports", "d", playerid);
    SetPVarInt(playerid, "pReport_Start", iStart);
    return 1;
}

forward thread_LoadReports(playerid);
public thread_LoadReports(playerid)
{//place your ConnectionHandle var
    new row, rows, fields, reportid, username[MAX_PLAYER_NAME], dest[64], BigVar[512]; // you might need a large string length
    cache_get_data(rows, fields);
    if(rows > 0)
    {
        while(row < rows)
        {
            cache_get_row(row, 0, dest, ConnectionHandle); // fix the connection handle
            reportid = strval(dest);
            cache_get_row(row, 1, username, ConnectionHandle);
            cache_get_row(row, 2, dest, ConnectionHandle);
            format(BigVar, sizeof(BigVar), "[%d] [%s]: %s", row, username, dest);
            ++row;
        }
        ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LISTITEM, "Report Log", BigVar, "Select", "Close");
    }
    else
    {
        DeletePVar(playerid, "pReport_Start");
        ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Report Log", "There are no reports in this criteria", "Close", "");
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case dialogid:
        {
            if(!response)
            {
                DeletePVar(playerid, "pReport_Start");
                 // put your shit here
                return 1;
            }
            new szQuery[96];
            format(szQuery, sizeof(szQuery), "SELECT * FROM `reportsLog` WHERE `reportID` = %d LIMIT 0, 1", GetPVarInt(playerid, "pReport_Start") + listitem);
            mysql_function_query(1, szQuery, true, "thread_LoadReportInformation", "d", playerid);
        }
    }
    return 1;
}

forward thread_LoadReportInformation(playerid);
public thread_LoadReportInformation(playerid)
{
    new rows, fields, reportid, username_er[MAX_PLAYER_NAME],
        username_ed[MAX_PLAYER_NAME], dest[64], timestamp[32], BigVar[256];
    cache_get_data(rows, fields);
    if(rows > 0)
    {
        cache_get_row(row, 0, dest, ConnectionHandle); // fix the connection handle
        reportid = strval(dest);
        cache_get_row(row, 1, username_er, ConnectionHandle);
        cache_get_row(row, 2, username_ed, ConnectionHandle);
        cache_get_row(row, 4, dest, ConnectionHandle);
        cache_get_row(row, 5, timestamp, ConnectionHandle); // is timestamp a string or what?
        format(BigVar, sizeof(BigVar), "[%d] - Information On %s\n\nReported By %s\nTime: %s\nReason: %s", reportid, username_ed, username_er, timestamp, dest);
        ++row;
    }
    ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LISTITEM, "Report Log Info", BigVar, "Back", "Close"); // make a feature to go back through ondialogresponse!
    return 1;
}
That should be good for now. Goodluck I think that's a good bit I GTG for now.
Reply


Messages In This Thread
Display results from DB into a dialog - by Scenario - 27.11.2012, 00:04
Re: Display results from DB into a dialog - by mastermax7777 - 27.11.2012, 00:08
Re: Display results from DB into a dialog - by Scenario - 27.11.2012, 00:10
Re: Display results from DB into a dialog - by Kar - 27.11.2012, 00:12
Re: Display results from DB into a dialog - by Scenario - 27.11.2012, 00:20
Re: Display results from DB into a dialog - by Kar - 27.11.2012, 00:25
Re: Display results from DB into a dialog - by Scenario - 27.11.2012, 00:32
Re: Display results from DB into a dialog - by Kar - 27.11.2012, 00:44
Re: Display results from DB into a dialog - by Scenario - 27.11.2012, 00:47

Forum Jump:


Users browsing this thread: 5 Guest(s)