Basing a boolean function on MySQL data
#6

Quote:
Originally Posted by Partner
Посмотреть сообщение
Could you give me a quick example ?
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_format
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_pquery
https://sampwiki.blast.hk/wiki/MySQL/R33#cache_get_row_int

A little example[Not totally sure if this is correct or not, I don't script PAWN for ages]
pawn Код:
forward Query_IPBanned();

stock CheckBan(ban[]) {
    new query[128], ip[16]; // IPV4 max size is 15 chars, so 16chars with the null('\0') in the end, IPV6 is not supported yet on SA-MP
    mysql_real_escape_string(ban, ip);
    mysql_format(connection_handle, query, 128, "SELECT COUNT(*) FROM `bans` WHERE `IP` = '%s'", ip);
    mysql_pquery(connection_handle, query, "Query_IPBanned");
}

public Query_IPBanned() {
    new count = cache_get_row_int(0,0); // get the row 0, field 0, which contains the output of COUNT.
    if(count >= 1) {
         // ip banned
    } else {
         // ip not banned
    }  
}
By the way, change the "COUNT(*)" for "COUNT(<primary key>)"

I hope this helps you out!
Reply


Messages In This Thread
Basing a boolean function on MySQL data - by Partner - 30.10.2014, 22:07
Re: Basing a boolean function on MySQL data - by Djole1337 - 30.10.2014, 22:13
Re: Basing a boolean function on MySQL data - by GWMPT - 30.10.2014, 22:21
Re: Basing a boolean function on MySQL data - by Partner - 31.10.2014, 08:02
Re: Basing a boolean function on MySQL data - by Partner - 31.10.2014, 09:09
Re: Basing a boolean function on MySQL data - by GWMPT - 31.10.2014, 11:02
Re: Basing a boolean function on MySQL data - by Vince - 31.10.2014, 11:10
Re: Basing a boolean function on MySQL data - by Partner - 31.10.2014, 11:17
Re: Basing a boolean function on MySQL data - by GWMPT - 31.10.2014, 11:19

Forum Jump:


Users browsing this thread: 4 Guest(s)