From a3d3aeadf6db22fd7e20c8c44b0b2c88cfc7fd37 Mon Sep 17 00:00:00 2001 From: cortylal <alexcortyl@gmail.com> Date: Thu, 19 Jun 2014 02:46:28 +0200 Subject: [PATCH] stats --- class/stats.php | 10 ++++++---- view/stats.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/class/stats.php b/class/stats.php index 67412db..c98edb0 100644 --- a/class/stats.php +++ b/class/stats.php @@ -170,14 +170,15 @@ class Stats { $bdd = new Db(); - $requete_prepare = $bdd->db->prepare(" SELECT r.nom, count(*) + $requete_prepare = $bdd->db->prepare(" SELECT r.nom, count(*) AS count FROM animal a, race r WHERE a.race = r.id GROUP BY r.nom, r.id + ORDER BY count DESC LIMIT 10" ); // on prépare notre requête $requete_prepare->execute(); - $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC); + $ligne = $requete_prepare->fetchAll(PDO::FETCH_ASSOC); return $ligne; } @@ -187,15 +188,16 @@ class Stats $bdd = new Db(); - $requete_prepare = $bdd->db->prepare(" SELECT e.nom, count(*) + $requete_prepare = $bdd->db->prepare(" SELECT e.nom, count(*) AS count FROM animal a, race r, espece e WHERE a.race = r.id AND e.id = r.espece GROUP BY e.nom, e.id + ORDER BY count DESC LIMIT 10" ); // on prépare notre requête $requete_prepare->execute(); - $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC); + $ligne = $requete_prepare->fetchAll(PDO::FETCH_ASSOC); return $ligne; } diff --git a/view/stats.php b/view/stats.php index 6547cd1..0ba063d 100644 --- a/view/stats.php +++ b/view/stats.php @@ -116,4 +116,40 @@ </tbody> </table> + <br/> + <hr/> + <h4>Top 10 des espèces clientes</h4> + <table class="table"> + <thead> + <th>Nom </th> + <th>Nombre d'individu </th> + </thead> + <tbody> + <?php foreach ($stats->top10Espece() as $ligne): ?> + <tr> + <td><?php echo $ligne["nom"]; ?> </td> + <td><?php echo $ligne["count"]; ?> </td> + </tr> + <?php endforeach; ?> + </tbody> + </table> + + <br/> + <hr/> + <h4>Top 10 des races clientes</h4> + <table class="table"> + <thead> + <th>Nom </th> + <th>Nombre d'individu' </th> + </thead> + <tbody> + <?php foreach ($stats->top10Race) as $ligne): ?> + <tr> + <td><?php echo $ligne["nom"]; ?> </td> + <td><?php echo $ligne["count"]; ?> </td> + </tr> + <?php endforeach; ?> + </tbody> + </table> + </div> \ No newline at end of file -- GitLab