Threaded query into a dialog? Doesn't seem to work.
#1

Basically, I'm trying to retrieve the Crime from the database to display in a dialog which can then be clicked, however it displays an empty dialog can anyone assist me?

pawn Код:
else if(dialogid == DIALOG_SHOWPERSON)  
            {
                if(response == 0)
                {
                    return 1;
                }
                else
                {
                    new string[256];
                    format(string, sizeof(string), "SELECT * FROM `arecords` WHERE `PSQLID` = %d ORDER BY `id` DESC LIMIT 10", psql[playerid]);
                    mysql_tquery(dbHandle, string, "GetRecord", "i", playerid);
                }
            }
pawn Код:
forward GetRecord(playerid);
public GetRecord(playerid)
{
    new r_msg[256], dialogstring[256], Rows = cache_get_row_count( );

    if(Rows < 1)return SendClientMessage(playerid, COLOUR_GREY, "No records found.");
    printf("%d rows", Rows);
    for(new n = 0; n < Rows; n++)
    {
        cache_get_row(n, 0, r_msg);
        sscanf(r_msg, "p<|>e<iiiis[24]iiii>", PlayerArrests[n]);
        cache_get_field_content(n, "Crime", PlayerArrests[n][ar_cr], 24);
        if(n == 0)
        {
            format(dialogstring, sizeof(dialogstring), ""#COL_WHITE"%s", PlayerArrests[n][ar_cr]);
        }
        else
        {
            format(dialogstring, sizeof(dialogstring), "%s\n"#COL_WHITE"%s", dialogstring, PlayerArrests[n][ar_cr]);
        }
    }

    strcpy(Pdialogstring[playerid], dialogstring, 200);
    ShowPlayerDialog(playerid, DIALOG_RECORDS, DIALOG_STYLE_LIST, "Showing 10 Latest Records.", dialogstring, "Select", "Back");
    return 1;
}
Reply
#2

cache_get_row does not work like this. You do not get a delimited string. Each column must be accessed individually and you cannot use sscanf.

Furthermore, since your entire message seems to be in white it seems counter productive to repeat the color code over and over again. It is much simpler to do it like so:
PHP код:
// before loop
dialogstring #COL_WHITE;

// in loop
cache_get_field_content(n"Crime"PlayerArrests[n][ar_cr], 24);

strcat(dialogstringPlayerArrests[n][ar_cr]);
strcat(dialogstring"\n"); 
Reply
#3

I actually didn't think you could use SSCANF. Thanks a lot for the heads up.
I completely forgot all about that until you mentioned it. Thank you very much.

The messages are white because I recently changed to threaded queries and the way I processed it before meant that it would change colour if the crime was unresolved, but I changed that and just haven't changed the string format.

I appreciate your help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)