Printing all rows with same IP
#1

I'm trying to print all the bans with the same ip,it detects the number of the same ban IPs, but it just prints out the first one's data.

pawn Код:
mysql_format(database, query, sizeof(query), "SELECT * FROM `bans` WHERE `ip` = '%e'", uData[target][pip]);
mysql_tquery(database, query, "BanCheck", "i", playerid);
pawn Код:
function:BanCheck(playerid)
{
    new
        rows, fields, ip[16], preason[20], adm[MAX_PLAYER_NAME], string[128], pname[MAX_PLAYER_NAME], bid, type, timeleft;
       
    cache_get_data(rows, fields, database);
   
    if(rows > 0)
    {  
       
        for(new i = 0; i < rows; i++)
        {
            bid = cache_get_field_content_int(0, "id");
            cache_get_field_content(0, "name", pname, database, MAX_PLAYER_NAME);
            cache_get_field_content(0, "ip", ip, database, 16);
            cache_get_field_content(0, "admin", adm, database, MAX_PLAYER_NAME);
            cache_get_field_content(0, "reason", preason, database, 20);
            type = cache_get_field_content_int(0, "btype");
            timeleft = cache_get_field_content_int(0, "utime");

            switch(type)
            {
                case 1: format(string, sizeof(string), "IP ban match found. BanID: %d Name: %s Reason: %s Admin: %s Type: Permanent.", bid, pname, preason, adm);
                case 2:
                {
                    new hours = floatround((timeleft - gettime()) / 60 / 60, floatround_round);
                    new minutes = floatround((timeleft - gettime()) / 60 % 60, floatround_round);
                    new seconds =  (timeleft - gettime()) % 60;
                    format(string, sizeof(string), "IP ban match found. BanID: %d Name: %s Reason: %s Admin: %s Type: Temporary Time left: %d hour(s) %d minute(s) %d second(s).", bid, pname, preason, adm, hours, minutes, seconds);
                }
            }
            SendClientMessage(playerid, COL_ADMIN, string);
        }
        return 1;
    }
    else SendClientMessage(playerid, COL_ADMIN, "No ban info found.");
   
    return 1;
}
print
Код:
IP ban match found. BanID: 1 Name: TEST Reason: test Admin: TEST Type: Temporary Time left: 4 hour(s) 6 minute(s) 51 second(s).
IP ban match found. BanID: 1 Name: TEST Reason: test Admin: TEST Type: Temporary Time left: 4 hour(s) 6 minute(s) 51 second(s).
While the second ban exist, it prints out the first ban info, instead of the second. It should print like this:
Код:
IP ban match found. BanID: 1 Name: TEST Reason: test Admin: TEST Type: Temporary Time left: 4 hour(s) 6 minute(s) 51 second(s).
IP ban match found. BanID: 2 Name: TEST_TEST Reason: test2 Admin: TEST Type: Temporary Time left: 4 hour(s) 6 minute(s) 51 second(s).
Reply
#2

That's because you always fetch row 0. Replace that with the loop counter (i).
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
That's because you always fetch row 0. Replace that with the loop counter (i).
Damn, didn't notice that. Thanks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)