Count bans in a MySQL system
#1

fixed
Reply
#2

Use the function mysql_num_rows It counts all the rows for ya!
Reply
#3

Quote:
Originally Posted by BlackRaven
Посмотреть сообщение
Use the function mysql_num_rows It counts all the rows for ya!
Like this?
pawn Код:
stock bancount(playerid)
{
    format(Query, sizeof(Query), "SELECT * FROM `banlog` WHERE (`name` = '%s' OR `ip` = '%s')  AND `banned` = 1 LIMIT 1", escpname(playerid), PIP);
    mysql_store_result();
    new rows = mysql_num_rows();
    mysql_free_result();
   
return rows;
}
When I add it on my string when a hack is detected, it says syntax error in the expression, or invalid func call
Reply
#4

Yes is that what i mean!
Reply
#5

Your query syntax is abit wrong, it will always select only one row, as you set LIMIT 1, in your case you should use
pawn Код:
new row[24];
    mysql_query( "SELECT COUNT(`name`) FROM `banlog` WHERE (`name` = '%s' OR `ip` = '%s')   AND `banned` = '1'" );
    mysql_store_result();
    mysql_fetch_row(row,"|")
    new Count = strval(row);
    mysql_free_result();
Reply
#6

Quote:
Originally Posted by ikey07
Посмотреть сообщение
Your query syntax is abit wrong, it will always select only one row, as you set LIMIT 1, in your case you should use
pawn Код:
new row[24];
    mysql_query( "SELECT COUNT(`name`) FROM `banlog` WHERE (`name` = '%s' OR `ip` = '%s')   AND `banned` = '1'" );
    mysql_store_result();
    mysql_fetch_row(row,"|")
    new Count = strval(row);
    mysql_free_result();
This stock
pawn Код:
stock bancount(playerid)
{
    new row[24];
    mysql_query( "SELECT COUNT(`name`) FROM `banlog` WHERE (`name` = '%s' OR `ip` = '%s')   AND `banned` = '1'" );
    mysql_store_result();
    mysql_fetch_row(row,"|");
    new Count = strval(row);
    mysql_free_result();
return rows;
}
returns as a syntax error, on this line
pawn Код:
format(string2, 130, "{FFFFFF}%s banned {FF9900}%s(%d){FFFFFF} for Spamming. %s banned %d players",anticheat, sendername,playerid,anticheat,bancount);
Reply
#7

Код:
SELECT COUNT(*)
FROM `banlog`
WHERE `banned` = 1
GROUP BY name
Will return the number of users banned. If you can solve your problem in the query, as opposed to using more functions in pawn afterwards, do it.
Reply
#8

Quote:
Originally Posted by Sinner
Посмотреть сообщение
Код:
SELECT COUNT(*)
FROM `banlog`
WHERE `banned` = 1
GROUP BY name
Will return the number of users banned. If you can solve your problem in the query, as opposed to using more functions in pawn afterwards, do it.
Being a noob n' all and still just learning MySQL
I came up with this:
pawn Код:
stock bancount(playerid)
{
    new row[24];
    mysql_query( "SELECT COUNT(`name`) FROM `banlog` WHERE `banned` = '1' GROUP BY name" );
    mysql_store_result();
    mysql_free_result();
return 1;
}
Am I doing it wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)