PDA

View Full Version : Mysql count players in clan


Admigo
20/06/2013, 03:07 PM
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

Niko_boy
20/06/2013, 03:17 PM
SELECT COUNT(*) FROM TABLE WHERE CLAN = CLANNAME

Vince
20/06/2013, 03:21 PM
Assuming you have two tables. One table that defines clans and its properties, and another one that defines its members.


SELECT COUNT(*)
FROM clan_members
WHERE clanid = %d
GROUP BY clanid


Something like that. Where %d represents your Pawn variable.

Admigo
21/06/2013, 02:42 PM
SELECT COUNT(*) FROM TABLE WHERE CLAN = CLANNAME

And how to return the result?

Niko_boy
23/06/2013, 05:27 AM
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)

Admigo
23/06/2013, 07:47 AM
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.

Vince
23/06/2013, 10:18 AM
This is pretty much the simples of SQL queries that exist. I suggest you read up on SQL some more.

SELECT playername FROM clan_members WHERE clanname = 'blah'

Then use a while-loop to fetch results.

Admigo
23/06/2013, 11:15 AM
This is pretty much the simples of SQL queries that exist. I suggest you read up on SQL some more.

SELECT playername FROM clan_members WHERE clanname = 'blah'

Then use a while-loop to fetch results.

I already have that.
Whats wrong with this:
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

Stylock
23/06/2013, 12:52 PM
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.

Admigo
23/06/2013, 12:57 PM
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.
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;
}
clanname|playername
Server log:
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.

Stylock
23/06/2013, 01:29 PM
Try using mysql_retrieve_row instead of mysql_fetch_row_format.

Admigo
23/06/2013, 01:42 PM
Try using mysql_retrieve_row instead of mysql_fetch_row_format.

You just fixed my problem. Thanks;)