SA-MP Forums Archive
Count bans in a MySQL system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Count bans in a MySQL system (/showthread.php?tid=411723)



Count bans in a MySQL system - Neil. - 30.01.2013

fixed


Re: Count bans in a MySQL system - BlackRaven - 30.01.2013

Use the function mysql_num_rows It counts all the rows for ya!


Re: Count bans in a MySQL system - Neil. - 30.01.2013

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


Re: Count bans in a MySQL system - BlackRaven - 30.01.2013

Yes is that what i mean!


Re: Count bans in a MySQL system - ikey07 - 30.01.2013

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();



Re: Count bans in a MySQL system - Neil. - 30.01.2013

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);



Re: Count bans in a MySQL system - Sinner - 30.01.2013

Код:
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.


Re: Count bans in a MySQL system - Neil. - 30.01.2013

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?