

<?php

$conn=pg_pconnect("dbname=emecmistica user=postgres"); 

//stats2
include "tete.php3";
?>
<H1>Sexo de los soci@s de la Communidad Virtual</H1><br>
<?
$male=0;
$fem=0;
$inconnu=0;
$members=0;
$queryview = pg_exec($conn,"select sexo from communidad where id_miembro>'2'");
?>
<table>
<tr><strong><td>M</td><td>F</td><td>I</td><td>SUMA</td></strong><tr>
<?
for($y=0; $y<pg_numrows($queryview); $y++) {
$get = pg_fetch_row($queryview,$y);
$sexo=trim($get[0]);
if ($sexo=="M") {
$male++;
}
elseif ($sexo=="F") {
$fem++;
}
elseif($sexo=="I") {
$inconnu++;
}
$members++;
}
echo "<tr><td>$male</td><td> $fem</td> <td>$inconnu</td><td> $members</td><tr>";
$pourcentmale=($male *100)/ $members;
$pourcentfem=($fem*100)/$members;
$pourcenti=($inconnu*100)/ $members;
$tabmale=explode(".", $pourcentmale);
$tabmale[1]=substr($tabmale[1], 0, 2);
$pourcentmale=implode(".", $tabmale);
$tabfem=explode(".", $pourcentfem);
$tabfem[1]=substr($tabfem[1], 0, 2);
$pourcentfem=implode(".", $tabfem);
$tabi=explode(".", $pourcenti);
$tabi[1]=substr($tabi[1], 0, 2);
$pourcenti=implode(".", $tabi);

echo "<tr><td>$pourcentmale %</td><td> $pourcentfem %</td> <td>$pourcenti %</td><td> </td><tr>";

?>
</table> 

<H1>Los paises de los soci@s</H1><br> 

<table>
<?
$compteur=0;
$querypais=pg_exec($conn,"select id_pais, pais_es from pais order by pais_es");
for ($tx=0; $tx<pg_numrows($querypais); $tx++) {
$getpaisx=pg_fetch_row($querypais, $tx);
$queryviewpais = pg_exec($conn,"select count(id_miembro) from communidad where id_pais=$getpaisx[0]");
$getpais=pg_fetch_row($queryviewpais, 0);
$nb=$getpais[0];
$compteur=$compteur+$nb;
$pais=stripslashes($getpaisx[1]);
$pais=ucwords($pais);
$pournb=($nb *100)/ $members;
$tabnb=explode(".", $pournb);
$tabnb[1]=substr($tabnb[1], 0, 2);
$pournb=implode(".", $tabnb);
if ($nb !=0) {
echo "<tr><td><strong>$pais</strong></td><td> $nb</td> <td>$pournb %</td><tr>";
}
}
$nbnul=$members-$compteur;
$pournul=($nbnul *100)/ $members;
$tabnul=explode(".", $pournul);
$tabnul[1]=substr($tabnul[1], 0, 2);
$pournul=implode(".", $tabnul);
echo "<tr><td><strong>Desconocido</strong></td><td> $nbnul</td> <td>$pournul %</td><tr>";
echo "<tr><td><strong>Total</strong></td><td> $members</td> <td></td><tr>";
?>
</table>


<br>
<br>
<?
$hui=time();

$hui=date("d/m/Y", $hui);
$exphui=explode ("/", $hui);
$ann=$exphui[2];

$arraytranche1=array("0");
$arraytranche2=array("0");
$arraytranche3=array("0");
$arraytranche4=array("0");
$arraytranche5=array("0");
$arraytranche6=array("0");
$arraytranche7=array("0");
$arraytranche8=array("0");
$c1=0;
$c2=0;
$c3=0;
$c4=0;
$c5=0;
$c6=0;
$c7=0;
$c8=0;
//les ages 
// tranches
$tranche1=$ann-25;
$tranche2=$ann-30;
$tranche3=$ann-35;
$tranche4=$ann-40;
$tranche5=$ann-45;
$tranche6=$ann-50;
$tranche7=$ann-55;

$qindet=pg_exec($conn, "select id_miembro, edad from communidad where id_miembro>'2'");
$nbmem=pg_numrows($qindet);
for($f; $f<pg_numrows($qindet); $f++) {
$getage=pg_fetch_row($qindet, $f);
if ($getage[1]>=$tranche1) {
$arraytranche1[$c1]=$getage[0];
$c1++;
}
elseif (($getage[1]<$tranche1) && ($getage[1]>=$tranche2)) {
$arraytranche2[$c2]=$getage[0];
$c2++;
}
elseif (($getage[1]<$tranche2) && ($getage[1]>=$tranche3)) {
$arraytranche3[$c3]=$getage[0];
$c3++;
}
elseif (($getage[1]<$tranche3) && ($getage[1]>=$tranche4)) {
$arraytranche4[$c4]=$getage[0];
$c4++;
}
elseif (($getage[1]<$tranche4) && ($getage[1]>=$tranche5)) {
$arraytranche5[$c5]=$getage[0];
$c5++;
}
elseif (($getage[1]<$tranche5) && ($getage[1]>=$tranche6)) {
$arraytranche6[$c6]=$getage[0];
$c6++;
}
elseif (($getage[1]<$tranche6) && ($getage[1]>=$tranche7)) {
$arraytranche7[$c7]=$getage[0];
$c7++;
}
elseif ($getage[1]<$tranche7) {
$arraytranche8[$c8]=$getage[0];
$c8++;
}
}
$c1=count($arraytranche1);
$c2=count($arraytranche2);
$c3=count($arraytranche3);
$c4=count($arraytranche4);
$c5=count($arraytranche5);
$c6=count($arraytranche6);
$c7=count($arraytranche7);
$c8=count($arraytranche8);
$c9=$nbmem-($c1+$c2+$c3+$c4+$c5+$c6+$c7+$c8);
//pourcentages
function pourcentage ($g, $m) {
$pourcent=($g *100)/ $m;
$tabcent=explode(".", $pourcent);
$tabcent[1]=substr($tabcent[1], 0, 2);
$pourc=implode(".", $tabcent);
return $pourc;
}
$p1=pourcentage($c1, $nbmem);
$p2=pourcentage($c2, $nbmem);
$p3=pourcentage($c3, $nbmem);
$p4=pourcentage($c4, $nbmem);
$p5=pourcentage($c5, $nbmem);
$p6=pourcentage($c6, $nbmem);
$p7=pourcentage($c7, $nbmem);
$p8=pourcentage($c8, $nbmem);
$p9=pourcentage($c9, $nbmem);



echo"<H1>EDADES </H1><br><table><tr><td><25</td><td>$c1</td><td>$p1</td></tr><tr><td>26-30</td><td>$c2</td><td>$p2</td></tr><tr><td>31-35</td><td>$c3</td><td>$p3</td></tr><tr><td>36-40</td><td>$c4</td><td>$p4</td></tr><tr><td>41-45</td><td>$c5</td><td>$p5</td></tr><tr><td>46-50</td><td>$c6</td><td>$p6</td></tr><tr><td>51-55</td><td>$c7</td><td>$p7</td></tr><tr><td>>56</td><td>$c8</td><td>$p8</td></tr><tr><td>?</td><td>$c9</td><td>$p9</td></tr></table>";
?>
