Jump to content

MySQL count


Thomisback

Recommended Posts

Hi,

 

I am trying to execute a MySQL query to find out how many members a game has, let me show you an example:

 

members          owner

 

12                  admin

39                  john

1                    john

21                  admin

 

How can I count up the total members from the same owners?

I have already tried various counts querys but they still do not count up the members from the same owners.

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/99931-mysql-count/
Share on other sites

Try this:

<?php
$i = 0;
$select = mysql_query("SELECT * FROM table");
while($info = mysql_fetch_array($select)) {
   if(array_key_exists($info['owner'],$users)) {
      $users[$info['owner']] = $users[$info['owner']] + $info['members'];
   }else{
      $users[$i] = $info['owner'] => $info['members'];
   }
}
print_r($users);
?>

 

I hope this helps you I hand coded this in the textbox so there may be some errors.

Link to comment
https://forums.phpfreaks.com/topic/99931-mysql-count/#findComment-510981
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.