SA-MP Forums Archive
Mysql count players in clan - 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: Mysql count players in clan (/showthread.php?tid=445259)



Mysql count players in clan - Admigo - 20.06.2013

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


Re: Mysql count players in clan - Niko_boy - 20.06.2013

SELECT COUNT(*) FROM TABLE WHERE CLAN = CLANNAME


Re: Mysql count players in clan - Vince - 20.06.2013

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.


Re: Mysql count players in clan - Admigo - 21.06.2013

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


Re: Mysql count players in clan - Niko_boy - 23.06.2013

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)


Re: Mysql count players in clan - Admigo - 23.06.2013

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.


Re: Mysql count players in clan - Vince - 23.06.2013

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.


Re: Mysql count players in clan - Admigo - 23.06.2013

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


Re: Mysql count players in clan - Stylock - 23.06.2013

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.


Re: Mysql count players in clan - Admigo - 23.06.2013

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.