Counting players MYSQL
#1

Cant get to work this code
I am trying to count all members from the faction but it doesnt works
pawn Код:
new query [ 124 ];
    format(query, sizeof(query), "SELECT Faction FROM players WHERE Faction = '%s'", PlayerInfo[playerid][playerteam]);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    mysql_free_result();
and then iam using it like this
pawn Код:
format(iStr, sizeof(iStr), " F-Members: %d/%d", rows, dini_Int(tmpf,"fmemberslots"));
        SendClientMessage(playerid, COLOR_WHITE, iStr);
But its displaying 0 while there are more then 3 members.
Whats wrong here?
Reply
#2

SELECT NULL FROM players WHERE Faction = '%s'
Reply
#3

I think you can make under on player connect,if playerinfo playerid......pmember =fbi
Fbimembers++;
And when someone want to check it shows him the fbimembers and under on player disconnect
If.....pmember=fbi
Fbimembers--;
Reply
#4

Now it just shows -1?
Also i have another problem,
pawn Код:
new query [ 60 ];
    new playername[24];
    GetPlayerName(iPlayer, playername, sizeof(playername));
    format(query, sizeof(query), "UPDATE `Factions` SET `leader`='%s' WHERE `famid`=%d",playername,iFaction);
    mysql_query(query);
It doesnt updates sthe leader in the table whats wrong here?
Reply
#5

Check mysql debug for query errors
Reply
#6

Quote:
Originally Posted by MadafakaPro
Посмотреть сообщение
Cant get `players` his code
I am trying to count all members from the faction but it doesnt works
pawn Код:
new query [ 124 ];
    format(query, sizeof(query), "SELECT Faction FROM players WHERE Faction = '%s'", PlayerInfo[playerid][playerteam]);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    mysql_free_result();
and then iam using it like this
pawn Код:
format(iStr, sizeof(iStr), " F-Members: %d/%d", rows, dini_Int(tmpf,"fmemberslots"));
        SendClientMessage(playerid, COLOR_WHITE, iStr);
But its displaying 0 while there are more then 3 members.
Whats wrong here?
The query should be -
pawn Код:
SELECT * FROM `players` WHERE `Faction` = '%s'
As for the second problem, query size is insufficient. 47 characters for syntax plus 24 for player name and 1/2 for family ID - means, minimum size should be 73/74.
Reply
#7

I do not know your entire database structure - so I can't guarantee anything - but I believe this is the query you want;
PHP код:
SELECT FactionCOUNT(*) AS Members FROM players GROUP BY Faction HAVING Faction '%s' 
If you omit the HAVING Faction part then it will show a list of all factions and the amount of members.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)