SA-MP Forums Archive
SQLite results question - 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)
+--- Thread: SQLite results question (/showthread.php?tid=423466)



SQLite results question - xXShadowXx - 17.03.2013

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.


Re: SQLite results question - Jefff - 17.03.2013

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



Re: SQLite results question - Konstantinos - 17.03.2013

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



Re: SQLite results question - xXShadowXx - 17.03.2013

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.