SQLite results question
#1

pawn Код:
CMD:aka(playerid,params[])
{
    new ID,DBResult:Result,Query[250];
    if(sscanf(params,"u",ID)) return SendClientMessage(playerid,-1,"USAGE: /aka [playerid]");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,-1,"ERROR: Player not connected.");
    format(Query,sizeof(Query),"SELECT * FROM `Accounts` WHERE `IP` = '%s'",IP[ID]);
    Result = db_query(DB,Query);
    // How would I get the names?
    db_free_result(Result);
    return 1;
}
how would i get the players names from the result?

thanks in advance.
Reply
#2

pawn Код:
CMD:aka(playerid,params[])
{
    new ID,DBResult:Result,Query[70];
    if(sscanf(params,"u",ID)) SendClientMessage(playerid,-1,"USAGE: /aka [playerid]");
    else if(!IsPlayerConnected(ID)) SendClientMessage(playerid,-1,"ERROR: Player not connected.");
    else{
        format(Query,sizeof(Query),"SELECT * FROM `Accounts` WHERE `IP` = '%s'",IP[ID]);
        Result = db_query(DB,Query);
        if(!db_num_rows(Result)) SendClientMessage(playerid,-1,"ERROR: Results not found.");
        else{
            new Nick[MAX_PLAYER_NAME + 1];

            do
            {
                db_get_field_assoc(Result, "Name", Nick, sizeof(Nick)); // replace 'Name' to your real column name with player nicknames
                SendClientMessage(playerid, -1, Nick);
            }
            while(db_next_row(Result))
        }
        db_free_result(Result);
    }
    return 1;
}
Reply
#3

Why a loop, Jefff? It can be done with an easier way though.

pawn Код:
CMD:aka(playerid,params[])
{
    new ID,DBResult:Result,Query[250];
    if(sscanf(params,"u",ID)) return SendClientMessage(playerid,-1,"USAGE: /aka [playerid]");
    if(!IsPlayerConnected(ID)) return SendClientMessage(playerid,-1,"ERROR: Player not connected.");
    format(Query,sizeof(Query),"SELECT * FROM `Accounts` WHERE `IP` = '%s'",IP[ID]);
    Result = db_query(DB,Query);
    if(db_num_rows(Result) == 1)
    {
        db_get_field_assoc(Result,"Field_Name_Here",Query,/* LENGHT/VALUE_OF_FIELD_HERE */);
    }
    db_free_result(Result);
    return 1;
}
Reply
#4

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
CMD:aka(playerid,params[])
{
    new ID,DBResult:Result,Query[70];
    if(sscanf(params,"u",ID)) SendClientMessage(playerid,-1,"USAGE: /aka [playerid]");
    else if(!IsPlayerConnected(ID)) SendClientMessage(playerid,-1,"ERROR: Player not connected.");
    else{
        format(Query,sizeof(Query),"SELECT * FROM `Accounts` WHERE `IP` = '%s'",IP[ID]);
        Result = db_query(DB,Query);
        if(!db_num_rows(Result)) SendClientMessage(playerid,-1,"ERROR: Results not found.");
        else{
            new Nick[MAX_PLAYER_NAME + 1];

            do
            {
                db_get_field_assoc(Result, "Name", Nick, sizeof(Nick)); // replace 'Name' to your real column name with player nicknames
                SendClientMessage(playerid, -1, Nick);
            }
            while(db_next_row(Result))
        }
        db_free_result(Result);
    }
    return 1;
}
thanks mate. +repped (sorry i can't give rep yet). thanks to you too Dwayne. +repped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)