Counting something from a MYSQL table -
PepsiCola23 - 17.11.2016
Hello guys,im kinda newbie in mysql scripting.
Today i want to get some tips on how to make a /factions cmd.
When you type /factions,it shows the faction name and the members in it
example:
PHP код:
Police Department- 5/10 members
,and also to count offline and online players.
On mysql i got 2 columns: Leader and Member.
I got an idea to count how for example for faction 1 [ police deparment] to count how many players have 1 on leader or member,but i dont really know how to do it.any tips?ty in advance
Re: Counting something from a MYSQL table -
JaKe Elite - 17.11.2016
When a new leader is assigned by an admin (or by anything), add the leader count and save them same goes to the member thingy.
Example;
PHP код:
enum urstruly
{
myLeader,
myMember
};
new itsMe[MAX_FACTIONS][urstruly];
// makeleader command
itsMe[id][myLeader] ++;
SaveFunction
// invite command
itsMe[id][myMember] ++;
SaveFunction
// faction kick
// Check if player is a leader here
{
itsMe[id][myLeader] --;
}
itsMe[id][myMember] --;
SaveFunction
Re: Counting something from a MYSQL table -
PepsiCola23 - 17.11.2016
i can`t really understand i think you got it wrong.
a want to make a function that can count from a mysql table `users` how many of them have Faction id 8 or stomething..
Re: Counting something from a MYSQL table -
Vince - 17.11.2016
You may want to check my tutorial on association tables in my sig. This is useful if a player can be a member of more than one faction, or if only a small fraction of the total players is a member of a faction. In the latter case you avoid cluttering the player's table with null values.
Counting rows is done using the COUNT() aggregate function. Very, very simple.
PHP код:
SELECT COUNT(Member) AS numMembers FROM User WHERE factionId = 8;
Alternatively, if you want a list of them all:
PHP код:
SELECT factionId, COUNT(*) as numMembers FROM User WHERE factionId > 0 GROUP BY factionId;
Re: Counting something from a MYSQL table -
PepsiCola23 - 17.11.2016
thanks bro,doing it right now :P