Mysql row into string
#1

its there any way to get a rom from mysql db and put that into string for example

i wonna check when player connect to servar to see if he is banned and if he is banned i wonna say

SendClientMessage(playerid,-1"You are banned from this servar:%s here %s",reason,time); something like that

table is collect bans and

reason row is called- reason

and for date is - time (2012-05-06 16:23:14)

please help me i will rep +
Reply
#2

Quote:
Originally Posted by [BG]PREDATOR
Посмотреть сообщение
its there any way to get a rom from mysql db and put that into string for example

i wonna check when player connect to servar to see if he is banned and if he is banned i wonna say

SendClientMessage(playerid,-1"You are banned from this servar:%s here %s",reason,time); something like that

table is collect bans and

reason row is called- reason

and for date is - time (2012-05-06 16:23:14)

please help me i will rep +
pawn Код:
new query[128];
format(query, sizeof(query), "SELECT `banned`,`ban_reason`,`ban_time` WHERE `player_name` = '%s'", GetPlayerName(playerid));
mysql_query(query)
mysql_store_result();

new results[128];
if(mysql_fetch_row_format(results, "|")
{
     sscanf(results, "p<|>dss", PlayerInfo[playerid][banned], ban_reason, ban_time);
}
mysql_free_result();
if(PlayerInfo[playerid][banned])
{
     format(query, sizeof(query), "You are banned for %s on %s", ban_reason, ban_time);
     SendClientMessage, COLOR_RED, query);
}
Reply
#3

my servar is mysql i dont have any enum for PlayerInfo[playerid][banned]
Reply
#4

Quote:
Originally Posted by [BG]PREDATOR
Посмотреть сообщение
my servar is mysql i dont have any enum for PlayerInfo[playerid][banned]
This is only an example of how you can make it. Use the variables you have.
Reply
#5

MySQL servers still have PlayerInfo because it's used to store player's data so you don't have to retrieve all of the player's data from the MySQL database all of the time, which is very slow.

To check if a player is banned, use this:

pawn Код:
new query[128];
GetPlayerName(playerid, query, sizeof(query));
format(query, sizeof(query), "SELECT `banned` FROM `users` WHERE `name` = '%s' AND `banned` = '1'", query);
mysql_query(query);
mysql_store_result();

if(mysql_num_rows())
{
    // banned
    return mysql_free_result();
}

mysql_free_result
Reply
#6

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
MySQL servers still have PlayerInfo because it's used to store player's data so you don't have to retrieve all of the player's data from the MySQL database all of the time, which is very slow.

To check if a player is banned, use this:

pawn Код:
new query[128];
GetPlayerName(playerid, query, sizeof(query));
format(query, sizeof(query), "SELECT `banned` FROM `users` WHERE `name` = '%s' AND `banned` = '1'", query);
mysql_query(query);
mysql_store_result();

if(mysql_num_rows())
{
    // banned
    return mysql_free_result();
}

mysql_free_result
That look eerily similar to my code.
Reply
#7

something like that but it give me error and one of them is Playerinfo
pawn Код:
public OnPlayerConnect(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT `username`,`reason`,`time` FROM `bans` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        // banned
        new results[128];
        if(mysql_fetch_row_format(results, "|")
        {//(281) : error 001: expected token: ")", but found "{"
            sscanf(results, "p<|>dss", PlayerInfo[playerid][banned], reason, time);//(282) : error 017: undefined symbol "PlayerInfo"
            /* stil errors from this line
                warning 215: expression has no effect
                error 001: expected token: ";", but found "]"
                error 029: invalid expression, assumed zero
            */

        }
        mysql_free_result();
        if(PlayerInfo[playerid][banned])
        {
            format(query, sizeof(query), "You are banned for %s on %s", reason, time);
            SendClientMessage, COLOR_RED, query);
        }
    }
    else
    {
        new Query[100];
        format(Query,sizeof(Query),"SELECT `username` FROM `playerdata` WHERE `username` = '%s'",PlayerName(playerid));
        mysql_query(Query);
        mysql_store_result();
        if(mysql_num_rows()>0)
        {
            new rstring[256];
            format(rstring,256,""WHITE"Welcome "GREEN"%s"WHITE" please type in password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login",rstring,"Continue","Exit");
        }
        else
        {
            new rstring[256];
            format(rstring,256,""RED"You are not register "WHITE"%s "RED"please enter your password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register",rstring,"Continue","Exit");

        }
        mysql_free_result();
    }
    return true;
}
Reply
#8

Quote:
Originally Posted by [BG]PREDATOR
Посмотреть сообщение
something like that but it give me error and one of them is Playerinfo
pawn Код:
public OnPlayerConnect(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT `username`,`reason`,`time` FROM `bans` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        // banned
        new results[128];
        if(mysql_fetch_row_format(results, "|")
        {//(281) : error 001: expected token: ")", but found "{"
            sscanf(results, "p<|>dss", PlayerInfo[playerid][banned], reason, time);//(282) : error 017: undefined symbol "PlayerInfo"
            /* stil errors from this line
                warning 215: expression has no effect
                error 001: expected token: ";", but found "]"
                error 029: invalid expression, assumed zero
            */

        }
        mysql_free_result();
        if(PlayerInfo[playerid][banned])
        {
            format(query, sizeof(query), "You are banned for %s on %s", reason, time);
            SendClientMessage, COLOR_RED, query);
        }
    }
    else
    {
        new Query[100];
        format(Query,sizeof(Query),"SELECT `username` FROM `playerdata` WHERE `username` = '%s'",PlayerName(playerid));
        mysql_query(Query);
        mysql_store_result();
        if(mysql_num_rows()>0)
        {
            new rstring[256];
            format(rstring,256,""WHITE"Welcome "GREEN"%s"WHITE" please type in password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login",rstring,"Continue","Exit");
        }
        else
        {
            new rstring[256];
            format(rstring,256,""RED"You are not register "WHITE"%s "RED"please enter your password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register",rstring,"Continue","Exit");

        }
        mysql_free_result();
    }
    return true;
}
GetPlayerName(playerid)
https://sampwiki.blast.hk/wiki/GetPlayerName
Reply
#9

Quote:
Originally Posted by [BG]PREDATOR
Посмотреть сообщение
something like that but it give me error and one of them is Playerinfo
pawn Код:
public OnPlayerConnect(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT `username`,`reason`,`time` FROM `bans` WHERE `username` = '%s'", PlayerName(playerid));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows())
    {
        // banned
        new results[128];
        if(mysql_fetch_row_format(results, "|")
        {//(281) : error 001: expected token: ")", but found "{" -- if(mysql_fetch_row_format(results, "|"))
            sscanf(results, "p<|>dss", PlayerInfo[playerid][banned], reason, time);//(282) : error 017: undefined symbol "PlayerInfo"
            /* stil errors from this line
                warning 215: expression has no effect
                error 001: expected token: ";", but found "]"
                error 029: invalid expression, assumed zero
                                Dont use PlayerInfo.....use your scripts player variables or enums
            */

        }
        mysql_free_result();
        if(PlayerInfo[playerid][banned])
        {
            format(query, sizeof(query), "You are banned for %s on %s", reason, time);
            SendClientMessage, COLOR_RED, query);
        }
    }
    else
    {
        new Query[100];
        format(Query,sizeof(Query),"SELECT `username` FROM `playerdata` WHERE `username` = '%s'",PlayerName(playerid));
        mysql_query(Query);
        mysql_store_result();
        if(mysql_num_rows()>0)
        {
            new rstring[256];
            format(rstring,256,""WHITE"Welcome "GREEN"%s"WHITE" please type in password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_PASSWORD,"Login",rstring,"Continue","Exit");
        }
        else
        {
            new rstring[256];
            format(rstring,256,""RED"You are not register "WHITE"%s "RED"please enter your password",PlayerName(playerid));
            ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_PASSWORD,"Register",rstring,"Continue","Exit");

        }
        mysql_free_result();
    }
    return true;
}
see the remarks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)