Create dialog from data out database[MySQL]
#1

Hello,

I have a dialog that shows the banned persons details, including BAN ID, username, reason, ip, and expire date.

BUt for some reason the last two don't want to show up correctly


As you can tell by yourself that's a weird looking IP and the expire date is when the UNIX time-stamps started.

The code:

pawn Code:
case DIALOG_BANLIST:
        {
            if(response)
            {
                new banString[800], expireDate[128];
                mtime_UnixToDate(expireDate, sizeof(expireDate), BanInfo[listitem][bUNIXExpire]);
                format(banString, sizeof(banString), "Ban ID: \t\t%d \nUsername:\t%s \nReason: \t%s \nIP: \t\t%s \nExpires on: \t%s ", BanInfo[listitem][bBanIndex], BanInfo[listitem][bBannedPlayer], BanInfo[listitem][bBanReason], BanInfo[listitem][bBannedIP], expireDate);
                ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_LIST, "Ban Information", banString, "Ok", "");
            }
        }
And the part where I fetch the MySQL data:
pawn Code:
for (new i = 0; i < rows; ++i)
            {
                while(mysql_fetch_row_format(banQuery, "|"))
                {
                    mysql_fetch_field_row(BanInfo[i][bBanIndex], "BanIndex");
                    mysql_fetch_field_row(BanInfo[i][bBannedPlayer], "BannedPlayer");
                    mysql_fetch_field_row(BanInfo[i][bBannedIP], "BannedIP");
                    mysql_fetch_field_row(BanInfo[i][bBanIssuer], "BanIssuer");
                    mysql_fetch_field_row(BanInfo[i][bBanReason], "BanReason");
                    mysql_fetch_field_row(BanInfo[i][bUNIXExpire], "UNIXExpire");
                    mysql_fetch_field_row(BanInfo[i][bUNIXBan], "UNIXBan");

                    strcat(finalString,BanInfo[i][bBannedPlayer]);
                    strcat(finalString,"\n");
                }
            }
            strcat(finalString, tmp);
            ShowPlayerDialog(playerid,DIALOG_BANLIST,DIALOG_STYLE_LIST, "{ff6600}Banlist", finalString,"Change","Cancel");

More information:

Saving it into enums:
pawn Code:
enum E_BAN_INFO
{
    bBanIndex,
    bBannedPlayer[MAX_PLAYER_NAME],
    bBanIssuer[MAX_PLAYER_NAME],
    bBanReason[128],
    bUNIXExpire,
    bUNIXBan,
    bBannedIP[30]
};
new BanInfo[MAX_BANS][E_BAN_INFO];
When banning someone:

pawn Code:
stock BanPlayer(playerid, playerBanner[], banReason[], banDays)
{
    new pName[MAX_PLAYER_NAME], escapedName[MAX_PLAYER_NAME], escapedActionName[MAX_PLAYER_NAME], safeReason[128], playerIp[16], banQuery[300];

    GetPlayerName(playerid, pName, sizeof(pName));
    mysql_real_escape_string(pName, escapedName);
    mysql_real_escape_string(playerBanner, escapedActionName);
    mysql_real_escape_string(banReason, safeReason);
    GetPlayerIp(playerid, playerIp, sizeof(playerIp));

    if(banDays == 0) { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, 0, 0, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime()); }
    else { format(banQuery, sizeof(banQuery), "INSERT INTO bans(BannedPlayer, BannedIP, BanIssuer, BanReason, UNIXBan, UNIXExpire, ShouldExpire, Expired) VALUES('%s', '%s', '%s', '%s', %i, %i, 1, 0)", escapedName, playerIp, escapedActionName, safeReason, gettime(), gettime() + (banDays * 86400)); }

    mysql_query(banQuery);

    KickEx(playerid, 5);
    return 1;
}


Anyone knows why this is like this?

And I've noticed if there are more players banned, and I click on another one, it sticks to 1. ANyone who can help me solve this also?
Reply
#2

For the IP, what field type are you using? I use Varchar to store IPs
Reply
#3

I'm using VARCHAR too.
Reply
#4

Anyone?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)