SA-MP Forums Archive
Counting players MYSQL - 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: Counting players MYSQL (/showthread.php?tid=487419)



Counting players MYSQL - MadafakaPro - 13.01.2014

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?


Re: Counting players MYSQL - iJumbo - 13.01.2014

SELECT NULL FROM players WHERE Faction = '%s'


Re: Counting players MYSQL - iBots - 13.01.2014

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--;


Re: Counting players MYSQL - MadafakaPro - 13.01.2014

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?


Re: Counting players MYSQL - iJumbo - 13.01.2014

Check mysql debug for query errors


Re: Counting players MYSQL - RajatPawar - 14.01.2014

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.


Re: Counting players MYSQL - Vince - 14.01.2014

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.