<?php

require("./.htconfig.php");

function readNbUserPerChannel()
{
    global $dblink;
    $result = array();
    $userCountPerChan = $dblink->query("SELECT anope_userstats_chan.channel, count(nickid) as nbuser FROM `anope_userstats_ison` inner join anope_userstats_chan on anope_userstats_chan. chanid=anope_userstats_ison.chanid inner join knacki_official ON knacki_official.channel = anope_userstats_chan.channel group by anope_userstats_chan.chanid order by channel");
    $userCountPerChan->setFetchMode(PDO::FETCH_OBJ);
    while ($i = $userCountPerChan->fetch())
	$result[$i->channel] = $i->nbuser;
    return $result;
}

function printNbUserPerChannelAsTable()
{
  ?><table>
      <tr>
	<th>Channel</th>
	<th>Connected user</th>
      </tr>
      <?php foreach(readNbUserPerChannel() as $channel => $usercount){ ?>
        <tr>
	  <td><?php echo $channel; ?></td>
	  <td><?php echo $usercount; ?></td>
	</tr>
      <?php } ?>
      </table><?php
}

?>
