[MySQL] GetPlayerAdminLevel(playerid)
#1

Hi im trying to make a include

pawn Код:
#if defined _test_included
  #endinput
#endif
#define _test_included

#include <mysql>

stock GetPlayerAdminLevel(playerid)
{
    new string[1337], playername[MAX_PLAYER_NAME], PlayerAdminLevel[2];
    GetPlayerName(playerid, playername, sizeof(playername));
   
    format(string, sizeof(string), "SELECT * FROM `Users` WHERE `Name` ='%s'", playername);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows())
    {
        mysql_fetch_field("AdminLevel", PlayerAdminLevel);
    }
    mysql_free_result();
    return PlayerAdminLevel;
}
but it dont get the right admin level, it sais "9" in phpMyAdmin but when i got in-game and test the function it sais "5"

so what are i doing wrong?

(im making a include so i can add it to filterscripts, like Lux Admin)
Reply
#2

Quote:
new string[1337], playername[MAX_PLAYER_NAME], PlayerAdminLevel[2];
GetPlayerName(playerid, playername, sizeof(playername));

format(string, sizeof(string), "SELECT * FROM `Users` WHERE `Name` ='%s'", playername);

what a waste of cells you use 39 + MAX_PLAYER_NAME = 59 cells max with this query... lol'd

also
Quote:

mysql_fetch_field
Use this function to get name of specific field.

not sure which mysql plugin are you using..

also you may want to return strval(PlayerAdminLevel) instead of a string.

are you sure you want to retrieve all fields? using "SELECT `AdminLevel` [..]" would be more reasonable I think..
Reply
#3

try it with "return strval(PlayerAdminLevel);"
Reply
#4

Quote:
Originally Posted by KoczkaHUN
Посмотреть сообщение
what a waste of cells you use 39 + MAX_PLAYER_NAME = 59 cells max with this query... lol'd

also

not sure which mysql plugin are you using..

also you may want to return strval(PlayerAdminLevel) instead of a string.

are you sure you want to retrieve all fields? using "SELECT `AdminLevel` [..]" would be more reasonable I think..
I know it is a waste.. i just typed something there.............................. (1337 = leet u know)

@Sascha - Thanks

Problem solved
Reply
#5

Код:
format(string, sizeof(string), "SELECT adminlevel FROM `Users` WHERE `Name` ='%s'", playername);
mysql_query(string);
return string;
No need to select the entire row.
Reply
#6

NVM i got it!
Reply
#7

i am wondering why people type exactly what i have written...
Reply
#8

pawn Код:
#if defined _test_included
  #endinput
#endif
#define _test_included

#include <mysql>

stock GetPlayerAdminLevel(playerid)
{
    new string[128], playername[MAX_PLAYER_NAME], PlayerAdminLevel;
    //You dont need 1337 string for these...and you off its size bellow
    //Admin level is integer (number) so you dont need it as string
    GetPlayerName(playerid, playername, sizeof(playername));
   
    format(string, sizeof(string), "SELECT * FROM `Users` WHERE `Name` ='%s'", playername);
    mysql_query(string);
    mysql_store_result();
    if(mysql_num_rows())
    {
        //You need to fetch already stored result not to store it to new variable
        mysql_fetch_field("AdminLevel", string);
        PlayerAdminLevel = strval(string);
    }
    mysql_free_result();
    return PlayerAdminLevel;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)