This topic was marked solved by its starter, on February 26th, 02:52 AM
findmemberclan something wrong with it?

AroliS^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 46
findmemberclan something wrong with it?
«  »
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.

dracc

  • Jr. Member
  • Posts: 84
Re: findmemberclan something wrong with it?
« Reply #1,  »Last edited
You're only checking the first row of the result data which means that the check
Code: [Select]
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:
Code: [Select]
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^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 46

dracc

  • Jr. Member
  • Posts: 84
Re: findmemberclan something wrong with it?
« Reply #3,  »
Try it like this?
Code: [Select]
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^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 46

dracc

  • Jr. Member
  • Posts: 84
Re: findmemberclan something wrong with it?
« Reply #5,  »
Previous code had a bug (could output both "you are not a member" and "you are a member"). Please consider using this instead:
Code: [Select]
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^

  • Newbie
  • Learning of Mike Tyson K.O
  • Posts: 46