findmemberclan something wrong with it?

Started by AroliS^, Feb 24, 2019, 08:39 PM

Previous topic - Next topic

AroliS^

this is a simple function to find clan members that i made

function FindMemberClan( player )
{
local q = QuerySQL( clanstat, "SELECT * FROM ClanUsers WHERE Clans LIKE '"+GetTag( player.Name )+"'" );
if ( q )
{
if (  GetSQLColumnData( q, 1 ) == player.Name )
{
 _MessagePlayer( white+"[ "+pink+GetTag( player.Name )+white+" ]- MEMBER: "+purple+TruncateClan( player.Name )+"", white+"[ "+pink+GetTag( player.Name )+white+" ]- MIEMBRO: "+purple+TruncateClan( player.Name )+"", player );
}
 else
{
 _MessagePlayer("You are not "+GetTag( player.Name )+" member you will be jailed and then kicked.", "No eres miembro de el clan "+GetTag( player.Name )+", seras encarcelado y despues kickeado.", player)
}
}
  FreeSQLQuery( q )
}

but only the first player registered in clan's database is recognized as a member what is wrong with it? here some pictures...

this is the database the first player is recognized as member the second one as not clan member.


first account, recognized.



second account, not recognized.
Lemme love ya

dracc

#1
You're only checking the first row of the result data which means that the check if (  GetSQLColumnData( q, 1 ) == player.Name ) never is true for anyone but the first player of the clan.

EDIT: What you want is probably something like this:
function FindMemberClan( player )
{
    local q = QuerySQL( clanstat, "SELECT * FROM ClanUsers WHERE Clans LIKE '" +
                        GetTag( player.Name )+"'" );
    if ( q )
    {
        while ( GetSQLNextRow(q) )
        {
            if ( GetSQLColumnData( q, 1 ) == player.Name )
            {
                _MessagePlayer( white + "[ " + pink + GetTag( player.Name ) + white +
                                " ]- MEMBER: " + purple + TruncateClan( player.Name ), player );
            }
            else
            {
                _MessagePlayer("You are not " + GetTag( player.Name ) +
                               " member you will be jailed and then kicked.", player);
            }
        }
    }
    FreeSQLQuery( q );
}

AroliS^

no work!  now either accounts are detected as members
Lemme love ya

dracc

Try it like this?
function FindMemberClan( player )
{
    local q = QuerySQL( clanstat, "SELECT * FROM ClanUsers WHERE Clans LIKE '" +
                        GetTag( player.Name )+"'" );
    if ( q )
    {
        do
        {
            if ( GetSQLColumnData( q, 1 ) == player.Name )
            {
                _MessagePlayer( white + "[ " + pink + GetTag( player.Name ) + white +
                                " ]- MEMBER: " + purple + TruncateClan( player.Name ), player );
            }
            else
            {
                _MessagePlayer("You are not " + GetTag( player.Name ) +
                               " member you will be jailed and then kicked.", player);
            }
        }
        while ( GetSQLNextRow(q) );
    }
    FreeSQLQuery( q );
}

AroliS^

Lemme love ya

dracc

Previous code had a bug (could output both "you are not a member" and "you are a member"). Please consider using this instead:
function FindMemberClan( player )
{
    local q = QuerySQL( clanstat, "SELECT * FROM ClanUsers WHERE Clans LIKE '" +
                        GetTag( player.Name )+"'" );
    if ( q )
    {
        do
        {
            if ( GetSQLColumnData( q, 1 ) == player.Name )
            {
                _MessagePlayer( white + "[ " + pink + GetTag( player.Name ) + white +
                                " ]- MEMBER: " + purple + TruncateClan( player.Name ), player );
                FreeSQLQuery( q );
                return;
            }
        }
        while ( GetSQLNextRow(q) );

        _MessagePlayer("You are not " + GetTag( player.Name ) +
                       " member you will be jailed and then kicked.", player);
    }
    else
    {
        print( "SQLite query failed" );
    }
    FreeSQLQuery( q );
}

AroliS^

Lemme love ya