SA-MP Forums Archive
help | again in mysql - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: help | again in mysql (/showthread.php?tid=261291)



help | again in mysql - EviLpRo - 12.06.2011

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!


Re: help | again in mysql - Scenario - 12.06.2011

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.


Re: help | again in mysql - Cyanide - 12.06.2011

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;
}



Re: help | again in mysql - Scenario - 12.06.2011

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.


Re: help | again in mysql - Cyanide - 12.06.2011

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.


Re: help | again in mysql - EviLpRo - 13.06.2011

thank you all !