26.12.2015, 10:25
Hi,
I've been using the cache variable like this whenever i need to fetch the result from the db.
I want to know if the way I am doing it is right or not? If someone can explain me about how to use it and how it functions, I'd be thankful.
I've been using the cache variable like this whenever i need to fetch the result from the db.
PHP Code:
IRCCMD:setofflevel(botid, channel[], user[], host[], params[]) {
if(IRC_IsOp(botid, channel, user)) {
new lvl;
if(sscanf(params, "s[24]i", params, lvl)) return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] Use: !setofflevel <username> <level>");
if(lvl > 6) return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] Invalid level.");
if(isuseronline(params))
return IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] This user is currently online.");
new Cache:result;
Query("SELECT `nick` FROM `users` WHERE `nick`='%e' ORDER BY `id`", params);
result = mysql_query(mysql, query);
if(!cache_get_row_count()) {
IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] The account with this username doesn't exist.");
cache_delete(result);
return 1;
}
new tmplvl = cache_get_field_content_int(0, "level");
if(lvl == tmplvl) {
IRC_GroupSay(groupID, IRC_CHANNEL, "4[Error] This user already has that level.");
cache_delete(result);
return 1;
}
if(lvl > tmplvl || lvl < tmplvl)
{
new id = cache_get_field_content_int(0, "id"), string[100];
Query("UPDATE `users` SET `level`='%i' WHERE `id`='%i'", lvl, id);
mysql_tquery(mysql, query, "QueryExecute", "i", result_none);
format:string("3[Info] You have set %s's admin level to %i", params, lvl);
IRC_GroupSay(groupID, IRC_CHANNEL, string);
}
cache_delete(result);
}
return 1;
}