Display results from DB into a dialog
#1

I can't seem to figure this out and I haven't really seen any examples I can understand... maybe one of you can help!

I have a table in my MySQL DB for reports. Each time someone does /report, all of the info from the report is inserted into the DB table. Now, I would like for administrators to be able to do /reports and the server will display a dialog which loads maybe the past 10-15 reports in the table. Maybe even give them the option to "Load More" and display the next 10-15 reports. Can someone help?

For what it's worth; all credits to any code will be added in the script!

EDIT: By the way, I'm using BlueG's MySQL plugin, R7 - not sure if this info. is needed or not though.
Reply
#2

whats ur code so far?

what's the problem? get columns, save in sscanf, put them on a string in dialog lol
Reply
#3

Unfortunately, I don't have any code for it now because I keep starting over.

What would be the query for retrieving the data, though? "SELECT * FROM `reportLog` LIMIT 15" maybe...?
Reply
#4

Let's work together, start the code and we'll guide you through it!

Your limit syntax is wrong for Select, it will work but I'm just saying

pawn Код:
SELECT * FROM `reportLog` LIMIT 0, 15
theres a start and a end so for your load more button you will edit that to like 16, 30 everytime you want to load more the vice versa
Reply
#5

Kar, you're awesome.

pawn Код:
CMD:reports(playerid, params[])
{
    if(pStats[playerid][pAdmin] < 1)
        return 1;

    new szQuery[200], iStart = 0, iEnd = 15;
    format(szQuery, sizeof(szQuery), "SELECT * FROM `reportsLog` LIMIT %d, %d", iStart, iEnd");
    mysql_function_query(1, szQuery, true, "
thread_LoadReports", "d", playerid);
    return 1;
}

forward thread_LoadReports(playerid);
public thread_LoadReports(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows)
    {
Stuck now.
Reply
#6

What are your tables?

I don't really know how you want it so heres a start

pawn Код:
CMD:reports(playerid, params[])
{
    if(pStats[playerid][pAdmin] < 1)
        return 1;

    new szQuery[96], iStart = 0, iEnd = 15;
    format(szQuery, sizeof(szQuery), "SELECT * FROM `reportsLog` LIMIT %d, %d", iStart, iEnd);
    mysql_function_query(1, szQuery, true, "thread_LoadReports", "d", playerid);
    return 1;
}

forward thread_LoadReports(playerid);
public thread_LoadReports(playerid)
{//place your ConnectionHandle var
    new row, rows, fields, dest[144], BigVar[1024]; // is 144 the max report length? it's a dialog right? so 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);
            format(BigVar, sizeof(BigVar), "Report ID [%d]: %s", row, dest);
            ++row;
        }
        ShowPlayerDialog(playerid, dialogid, MSGORLIST?, "Report Log", BigVar, "Select", "Close");
    }
    else
    {
        ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Report Log", "There are no reports in this criteria", "Close", "");
    }
    return 1;
}
Reply
#7

Oh, right, my fault. I'll list the field names in their proper order.

Код:
reportID, reporterUsername, reportedUsername, reportReason, reportTimestamp
What I am looking for is that all of those values will be loaded and pretty much represented like this in the dialog...

Quote:

[reportID] | [reportedUsername] [reportReason]

If you click on the report it will give you additional information, such as the time/date of the report and who the reporter was.

The reason length is about 60 characters long, at maximum.
Reply
#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
#9

You are a God among men, thanks Kar. That's all the help I'll need for this!

I gave you some rep. points, in case you didn't already notice.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)