help | again in mysql
#1

okay hello all !

Sorry that's how Northern Beacon the clusters help forum, but it's pretty urgent.
Why is it not even me?

Here's the code:

pawn Код:
format (String, 256, "Nick:%s", GetName (playerid));
SendClientMessage (playerid, c_orange, String);
format (String, 256, "Password:%s", inputtext);
SendClientMessage (playerid, c_orange, String);
format (String, 256, "Register Date:%s", GetDate ());
SendClientMessage (playerid, c_orange, String);
format (String, 256, "User Number:%s", GetPlayerNumberID (playerid));
SendClientMessage (playerid, c_orange, String);
Everything works well except the User Number, is the stock of GetPlayerNumberID:

pawn Код:
stock GetPlayerNumberID (playerid)
{
new query [256];
format (query, 256, "SELECT ID FROM Users WHERE Nick = '%s'", GetName (playerid));
return mysql_query (query);
}
Thanks in advance for helpers!
Reply
#2

You are returning the MySQL query rather than the query result; try this:

pawn Код:
stock GetPlayerNumberID (playerid)
{
    new query[256], szResult[25];
    format(query, sizeof(query), "SELECT `ID` FROM `Users` WHERE `Nick` = '%s'", GetName(playerid));
    mysql_query(query);
   
    mysql_store_result();
    mysql_fetch_row_format(szResult, "|"):
    return szResult;
}
It has not been tested and has been formatted to work with BlueG's MySQL plugin.
Reply
#3

Here's a more optimized and more efficient way of retrieving the ID without being bothered which plugin he/she is using.

pawn Код:
stock GetPlayerNumberID (playerid)
{
    static
         s_string[ 72 ],
         s_return
    ;
    GetPlayerName( playerid, s_string, MAX_PLAYER_NAME );
    format( s_string, sizeof s_string, "SELECT `ID` FROM `Users` WHERE `Nick` = '%s'", s_query );
    mysql_query( s_string );
   
    mysql_store_result( );
    s_return = mysql_fetch_int( );
    mysql_free_result( );
   
    return s_return;
}
Reply
#4

Quote:
Originally Posted by Cyanide
Посмотреть сообщение
Here's a more optimized and more efficient way of retrieving the ID without being bothered which plugin he/she is using.

pawn Код:
stock GetPlayerNumberID (playerid)
{
    static
         s_string[ 72 ],
         s_return
    ;
    GetPlayerName( playerid, s_string, MAX_PLAYER_NAME );
    format( s_string, sizeof s_string, "SELECT `ID` FROM `Users` WHERE `Nick` = '%s'", s_query );
    mysql_query( s_string );
   
    mysql_store_result( );
    s_return = mysql_fetch_int( );
    mysql_free_result( );
   
    return s_return;
}
I don't see much of a difference besides the fact that I forgot the "mysql_free_result()" function and you aren't using their custom "GetName" function.
Reply
#5

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I don't see much of a difference besides the fact that I forgot the "mysql_free_result()" function and you aren't using their custom "GetName" function.
Of course there cannot be much of a difference in such a small function. The reason for my edit was because the function mysql_fetch_int is faster than mysql_fetch_row_format, and wouldn't have to bother with whether someone is using different plugin or not. It would of been better anyhow if I left GetName out. If I put GetName in a parameter in the upcoming called format it would of created another useless variable when s_string could of been used.
Reply
#6

thank you all !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)