Mysql count players in clan
#1

Heey all,

How can i detect how much players is in a clan with mysql?
Example:
Код:
Admigo|clan1
Test1|clan1
Test2|clan2
Test3|clan2
Test4|clan1
So now it needs to return 3 players that are in my clan.

Admigo
Reply
#2

SELECT COUNT(*) FROM TABLE WHERE CLAN = CLANNAME
Reply
#3

Assuming you have two tables. One table that defines clans and its properties, and another one that defines its members.

PHP код:
SELECT COUNT(*)
FROM clan_members
WHERE clanid 
= %d
GROUP BY clanid 
Something like that. Where %d represents your Pawn variable.
Reply
#4

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
SELECT COUNT(*) FROM TABLE WHERE CLAN = CLANNAME
And how to return the result?
Reply
#5

Quote:
Originally Posted by Admigo
Посмотреть сообщение
And how to return the result?
try this:
SELECT COUNT(*) AS `CLANTOTAL` FROM TABLE WHERE CLAN = CLANNAME

later..
mysql_fetch_field_row(clanCount,"CLANTOTAL");
now u have ur value in clanCount.

(sorry for bump , i just noticed it while scrolling through forum)
Reply
#6

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
try this:
SELECT COUNT(*) AS `CLANTOTAL` FROM TABLE WHERE CLAN = CLANNAME

later..
mysql_fetch_field_row(clanCount,"CLANTOTAL");
now u have ur value in clanCount.

(sorry for bump , i just noticed it while scrolling through forum)
Thanks, do you also know how to return the players in a clan.
Example in DB:
Код:
PlayerName|ClanName
Admigo|Clan1
Test1|clan2
Test2|Clan1
so if i use like GetPlayerMembersInClan(clanname[]) and when i use Clan1 it will return in a string:
Код:
Admigo
Test2
It needs to be threaded.
Reply
#7

This is pretty much the simples of SQL queries that exist. I suggest you read up on SQL some more.

PHP код:
SELECT playername FROM clan_members WHERE clanname 'blah' 
Then use a while-loop to fetch results.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
This is pretty much the simples of SQL queries that exist. I suggest you read up on SQL some more.

PHP код:
SELECT playername FROM clan_members WHERE clanname 'blah' 
Then use a while-loop to fetch results.
I already have that.
Whats wrong with this:
pawn Код:
case _THREAD_GET_CLAN_MEMBERS :
        {
            new resultline[512];
            mysql_store_result();
            if(mysql_num_rows(gSQL) > 0)
            {
                while(mysql_fetch_row_format(resultline,"|"))
                {
                        mysql_fetch_field_row(resultline,"playername");
                        printf("%s\n",resultline);
                }
            }
            mysql_free_result();
        }
The printf returns blank
Reply
#9

Can you provide relevant table and column names? It's not clear to me whether you're storing the data in one or multiple tables.
Reply
#10

Quote:
Originally Posted by Stylock
Посмотреть сообщение
Can you provide relevant table and column names? It's not clear to me whether you're storing the data in one or multiple tables.
Sure.
pawn Код:
stock GetClanMembers(clan[])
{
        new clanquery[200];
        format(clanquery, sizeof(clanquery), "SELECT * FROM a_clans_members WHERE clanname = '%s'", clan);
        mysql_query(clanquery, _THREAD_GET_CLAN_MEMBERS, -1, gSQL);
        return 1;
}
pawn Код:
clanname|playername
Server log:
pawn Код:
15:29:29] >> mysql_query_callback(Connection handle: 1)
[15:29:29] ProcessQueryThread(OnQueryFinish) - Executing query SELECT * FROM a_clans_members WHERE clanname = 'acnr'...
[15:29:29] ProcessQueryThread(OnQueryFinish) - Query was successful.
[15:29:29] ProcessQueryThread(OnQueryFinish) - Data being passed to ProcessTick().
[15:29:29] OnQueryFinish(siii) - Callback is being called...
[15:29:29] >> mysql_store_result(Connection handle: 1)
[15:29:29] CMySQLHandler::StoreResult() - Result was stored.
[15:29:29] >> mysql_num_rows(Connection handle: 1)
[15:29:29] CMySQLHandler::NumRows() - Returned 2 row(s).
[15:29:29] >> mysql_fetch_row_format(Connection handle: 1)
[15:29:29] CMySQLHandler::FetchRow() - Return: 7|acnr|Admigo|10|1|1.
[15:29:29] >> mysql_fetch_field_row(Connection handle: 1)
[15:29:29] CMySQLHandler::FetchField(playername) - You cannot call this function now (no result).
[15:29:29] >> mysql_fetch_row_format(Connection handle: 1)
[15:29:29] CMySQLHandler::FetchRow() - Return: 7|acnr|Andy|1|1|2.
[15:29:29] >> mysql_fetch_field_row(Connection handle: 1)
[15:29:29] CMySQLHandler::FetchField(playername) - You cannot call this function now (no result).
[15:29:29] >> mysql_fetch_row_format(Connection handle: 1)
[15:29:29] >> mysql_free_result(Connection handle: 1)
[15:29:29] CMySQLHandler::FreeResult() - Result was successfully freed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)