Counting something from a MYSQL table
#1

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 Department5/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
Reply
#2

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 
Reply
#3

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..
Reply
#4

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 factionIdCOUNT(*) as numMembers FROM User WHERE factionId 0 GROUP BY factionId
Reply
#5

thanks bro,doing it right now :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)