Getting a value from another table
#1

So as the title says, that's where I need help at.

I have this command called !setoffscore, this is for IRC:

PHP код:

IRCCMD
:setoffscore(botidchannel[], user[], host[], params[])
{
    if(!
IRC_IsAdmin(botidchanneluser)) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You are don't have permission to use this command!");
    if(!
IsPlayerWhiteList(user)) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You are don't have permission to use this command!");
    new 
targetName[MAX_PLAYER_NAME], _query[150], scoreCache:results;
    if(
sscanf(params"s[24]d"score)) return IRC_Notice(gGroupIDuser,"\x0214[USAGE]:\x02 !setoffscore [username] [score]") && IRC_Notice(gGroupIDuser,"\x0214[FUNCTION]:\x0F Set an offline player's score");
    if(
IsValidAccount(targetName) == 0) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You have inputed an invalid account name!");
    
format(_querysizeof(_query), "UPDATE `accounts` SET `Hours` = %d WHERE `Username` = '%e'"scoretargetName);
    
mysql_tquery(handle_query);
    
format(_querysizeof(_query), "\x0203[INFO]:\x02 \x1D%s\x1D has set \x1D%s\x1D's score to \x1D%d\x1D"usertargetNamescore);
    
IRC_GroupSay(gGroupIDchannel_query);
    
SendToLog("!setscore"usertargetNamescore);
    return 
1;

I want to also set it from "stats" since we wanted to save "Hours" in 2 different tables ( there's other purpose behind it ) but the thing is we don't use "Username" on "stats" Instead, we use the AccountID of the Username from the table "accounts"

I've tried this:

PHP код:

IRCCMD
:setoffscore(botidchannel[], user[], host[], params[])
{
    if(!
IRC_IsAdmin(botidchanneluser)) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You are don't have permission to use this command!");
    if(!
IsPlayerWhiteList(user)) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You are don't have permission to use this command!");
    new 
targetName[MAX_PLAYER_NAME], _query[150], scoretargetIdCache:results;
    if(
sscanf(params"s[24]d"targetNamescore)) return IRC_Notice(gGroupIDuser,"\x0214[USAGE]:\x02 !setoffscore [username] [score]") && IRC_Notice(gGroupIDuser,"\x0214[FUNCTION]:\x0F Set an offline player's score");
    if(
IsValidAccount(targetName) == 0) return IRC_Notice(botiduser"\x0204[ERROR]:\x02 You have inputed an invalid account name!");
    
mysql_format(handle_querysizeof(_query), "SELECT `AccountID` FROM `accounts` WHERE `Username` = '%e'"targetName);
    
results mysql_query(handle_query);
    
cache_get_value_name_int(0"AccountID"targetId);
    
cache_delete(results);
    
format(_querysizeof(_query), "UPDATE `accounts` SET `Hours` = %d WHERE `Username` = '%e'"scoretargetName);
    
mysql_tquery(handle_query);
    
format(_querysizeof(_query), "UPDATE `stats` SET `Hours` = %d WHERE `AccountID` = '%d'"scoretargetId);
    
mysql_tquery(handle_query);
    
format(_querysizeof(_query), "\x0203[INFO]:\x02 \x1D%s\x1D has set \x1D%s\x1D's score to \x1D%d\x1D"usertargetNamescore);
    
IRC_GroupSay(gGroupIDchannel_query);
    
SendToLog("!setscore"usertargetNamescore);
    return 
1;

But it didn't worked, can you help me fix it, or at least figure out/help me out? Thanks. +rep for helping.
Reply
#2

Quote:
Originally Posted by DarkMythHunter
( there's other purpose behind it )
It's just hard to explain it. I just need this to work.
Reply
#3

It's not about getting away from the question, it's about me wondering why you necessarily need to know that. All I want is a help how will it work, not to change it to something else and remove another table.
Reply
#4

Alright, got it working. Thanks.
Reply
#5

Aight, sorry for that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)