CMD:searchban(playerid, params[]) {
new Query[240], string[128], NameOrIP[40], DBResult:Result;
if(!PlayerInfo[playerid][AdminLevel]) return SendClientMessage(playerid, COLOR_ORANGE, "NOTE: You need to be an admin!");
if(sscanf(params, "s[40]", NameOrIP)) return SendClientMessage(playerid, COLOR_NOTES, "USAGE: /searchban PLAYERNAME/PLAYERIP");
format(Query, sizeof(Query), "SELECT * FROM `BANNED` WHERE `NAME` LIKE '%s' OR `IP` LIKE '%s' ORDER BY `DATE` DESC LIMIT 6", NameOrIP, NameOrIP);
Result = db_query(HDF, Query);
if(db_num_rows(Result))
{
new BannedBy[24], BannedName[24], BannedIP[24], BannedReason[50];
do
{
db_get_field_assoc(Result, "NAME", BannedName, sizeof(BannedName));
db_get_field_assoc(Result, "IP", BannedIP, sizeof(BannedIP));
db_get_field_assoc(Result, "ADMIN", BannedBy, sizeof(BannedBy));
db_get_field_assoc(Result, "REASON", BannedReason, sizeof(BannedReason));
format(string, sizeof(string), "- %s(IP: %s) - banned by %s - due to %s", BannedName, BannedIP, BannedBy, BannedReason);
SendClientMessage(playerid, COLOR_NOTES2, string);
}
}
else SendClientMessage(playerid, COLOR_ORANGE, "NOTE: No bans found!");
db_free_result(Result); string = "\0", Query = "\0", NameOrIP = "\0";
return 1;
}
CMD:searchban(playerid, params[])
{
if(!PlayerInfo[playerid][AdminLevel]) SendClientMessage(playerid, COLOR_ORANGE, "NOTE: You need to be an admin!");
else if(isnull(params)) SendClientMessage(playerid, COLOR_NOTES, "USAGE: /searchban PLAYERNAME/PLAYERIP");
else{
new Query[240], string[145];
format(Query, sizeof(Query), "SELECT * FROM `BANNED` WHERE `NAME` LIKE '%s' OR `IP` LIKE '%s' ORDER BY `DATE` DESC LIMIT 6", params, params);
new DBResult:Result = db_query(HDF, Query);
if(db_num_rows(Result))
{
new BannedBy[MAX_PLAYER_NAME], BannedName[MAX_PLAYER_NAME], BannedIP[MAX_PLAYER_NAME], BannedReason[MAX_PLAYER_NAME*2];
do
{
db_get_field_assoc(Result, "NAME", BannedName, sizeof(BannedName));
db_get_field_assoc(Result, "IP", BannedIP, sizeof(BannedIP));
db_get_field_assoc(Result, "ADMIN", BannedBy, sizeof(BannedBy));
db_get_field_assoc(Result, "REASON", BannedReason, sizeof(BannedReason));
format(string, sizeof(string), "- %s(IP: %s) - banned by %s - due to %s", BannedName, BannedIP, BannedBy, BannedReason);
SendClientMessage(playerid, COLOR_NOTES2, string);
}
while(db_next_row(Result));
}
else SendClientMessage(playerid, COLOR_ORANGE, "NOTE: No bans found!");
db_free_result(Result);
}
return 1;
}
pawn Код:
|
There seems to be some bug when inserting a literal % where you need to do it like this %%%% yes I know it says to do %% but try this code here.
|
SELECT * FROM `BANNED` WHERE `NAME` LIKE '%%%s%%' OR `IP` LIKE '%s' ORDER BY `DATE` DESC LIMIT 6
Wildcards indeed.
SQL LIKE accepts wildcards, the one you want is '%', this tells the engine that there can be 0 or more missing letters there. %string% will give you what you need. Samp escapes the % sigh so you'll need to use %% Код:
SELECT * FROM `BANNED` WHERE `NAME` LIKE '%%%s%%' OR `IP` LIKE '%s' ORDER BY `DATE` DESC LIMIT 6 |