MySQL Wiz Biz -
DeathKing - 22.03.2016
Hey guys, to whoever is reading this... I need urgent help regarding my script about MySQL
Goal: Obtain the user's name through their respective account IDs
Error: Public functions cannot return arrays
Request: Help in finding a work around to the problem but still preserves the initial goal of the function
Код HTML:
stock UserFromID(ID)
{
new query[200];
mysql_format(MySQL, query, sizeof(query), "SELECT `Username` FROM `Users` WHERE `ID` = %d LIMIT 0,1", ID);
mysql_tquery(MySQL, query, "OnUserFromIDCheck", "i", ID);
return 1;
}
forward OnUserFromIDCheck(ID);
public OnUserFromIDCheck(ID)
{
new rows, fields, UserID[128];
cache_get_data(rows, fields, MySQL);
if(rows == 1)
{
cache_get_field_content(0, "Username", UserID, MySQL, sizeof(UserID));
} else format(UserID, sizeof(UserID), "");
return UserID;
}
Thank you in advance!
Re: MySQL Wiz Biz -
SickAttack - 22.03.2016
I don't think you realise what you are trying to do. Just use "UserID" inside the public function itself, there's no need to return a value. It's theoretically the same thing.
Re: MySQL Wiz Biz -
Sabur - 22.03.2016
Public functions can't return string, use stock.
Re: MySQL Wiz Biz -
SickAttack - 22.03.2016
Quote:
Originally Posted by Sabur
Public functions can't return string, use stock.
|
He shouldn't even be returning anything, just the usual "return 1;".
Re: MySQL Wiz Biz -
DeathKing - 22.03.2016
Quote:
Originally Posted by SickAttack
He shouldn't even be returning anything, just the usual "return 1;".
|
Actually... I should be just because i am trying to get the Name from the ID which then i stored to a variable that is returned my the public function there..
EDIT: So how do you suggest i store the value for global use?
Re: MySQL Wiz Biz -
introzen - 22.03.2016
Seeing you trying to store "Username" into "UserID" just f*cks my mind right up. Change it please.
OT: Why do you need to return it? Just set the variable inside the callback?
pawn Код:
stock UserFromID(ID)
{
new query[200];
mysql_format(MySQL, query, sizeof(query), "SELECT `Username` FROM `Users` WHERE `ID` = %d LIMIT 0,1", ID);
mysql_tquery(MySQL, query, "OnUserFromIDCheck", "i", ID);
return 1;
}
new UserNAME[MAX_PLAYERS];
forward OnUserFromIDCheck(ID);
public OnUserFromIDCheck(ID)
{
new rows, fields;
cache_get_data(rows, fields, MySQL);
if(rows == 1)
{
cache_get_field_content(0, "Username", UserNAME[ID], MySQL, MAX_PLAYER_NAME);
} else format(UserNAME[ID], MAX_PLAYER_NAME, "");
return 1;
}
Re: MySQL Wiz Biz -
jlalt - 22.03.2016
PHP код:
UserFromID(ID, UserID[MAX_PLAYER_NAME])
{
new query[200];
mysql_format(MySQL, query, sizeof(query), "SELECT `Username` FROM `Users` WHERE `ID` = %d LIMIT 0,1", ID);
new Cache:Result = mysql_query(MySQL, query);
if(cache_num_rows()) cache_get_field_content(0, "Username", UserID, MySQL, sizeof(UserID));
else UserID = "NULL";
cache_delete(Result);
return 1;
}
usage:
PHP код:
new name[MAX_PLAYER_NAME];
UserFromID(ID,name);
// THe Name will be player name you wanna get you can print it to see
printf("%s",name);
Re: MySQL Wiz Biz -
DeathKing - 22.03.2016
Quote:
Originally Posted by introzen
Seeing you trying to store "Username" into "UserID" just f*cks my mind right up. Change it please.
OT: Why do you need to return it? Just set the variable inside the callback?
pawn Код:
stock UserFromID(ID) { new query[200]; mysql_format(MySQL, query, sizeof(query), "SELECT `Username` FROM `Users` WHERE `ID` = %d LIMIT 0,1", ID); mysql_tquery(MySQL, query, "OnUserFromIDCheck", "i", ID); return 1; }
new UserNAME[MAX_PLAYERS]; forward OnUserFromIDCheck(ID); public OnUserFromIDCheck(ID) { new rows, fields; cache_get_data(rows, fields, MySQL);
if(rows == 1) { cache_get_field_content(0, "Username", UserNAME[ID], MySQL, MAX_PLAYER_NAME); } else format(UserNAME[ID], MAX_PLAYER_NAME, ""); return 1; }
|
Hmm sorry about that... Yeah it would but this Function like i said aims to be used globally in a sense that even the system in itself (Without the players) will use this.... so yeah....
Quote:
Originally Posted by jlalt
PHP код:
UserFromID(ID, UserID[MAX_PLAYER_NAME])
{
new query[200];
mysql_format(MySQL, query, sizeof(query), "SELECT `Username` FROM `Users` WHERE `ID` = %d LIMIT 0,1", ID);
new Cache:Result = mysql_query(MySQL, query);
if(cache_num_rows()) cache_get_field_content(0, "Username", UserID, MySQL, sizeof(UserID));
else UserID = "NULL";
cache_delete(Result);
return 1;
}
usage:
PHP код:
new name[MAX_PLAYER_NAME];
UserFromID(ID,name);
// THe Name will be player name you wanna get you can print it to see
printf("%s",name);
|
EDIT Second thought this might just work.. i'll go ahead and try it now
EDIT 2: Works well! Thanks jlalt