diff --git a/class/stats.php b/class/stats.php index 22b0913438373e2b91d3a784e9017c6de041f845..592bb1c9b7180a5a5961f79cc6cc6c37a6abd639 100644 --- a/class/stats.php +++ b/class/stats.php @@ -2,16 +2,12 @@ class Stats { - public function factureMoyClient() + public function factureMoy() { $bdd = new Db(); - $requete_prepare = $bdd->db->prepare(" SELECT SUM(t.prix)/COUNT(*) AS value - FROM ( SELECT c.nom, c.prenom, SUM(f.prix_total) AS prix - FROM animal a, client c, facture f - WHERE a.client = c.id - AND f.animal = a.id - GROUP BY c.nom, c.prenom, c.id) t" ); // on prépare notre requête + $requete_prepare = $bdd->db->prepare(" SELECT SUM(f.prix_total)/COUNT(*) + FROM facture f" ); // on prépare notre requête $requete_prepare->execute(); $ligne = $requete_prepare->fetch(PDO::FETCH_ASSOC); diff --git a/view/stats.php b/view/stats.php index 74fd2e6cfce777cdcc0da35e1a844f1408e88ed6..d352d80a22ca388a9093222c00f0d29822ca9eed 100644 --- a/view/stats.php +++ b/view/stats.php @@ -6,8 +6,8 @@ <table class="table"> <thead> - <th>Facture moyenne par client : </th> - <th><?php $tmp = $stats->factureMoyClient(); $nb_formated = number_format($tmp["value"], 2, ',', ' '); echo $nb_formated; ?></th> + <th>Facture moyenne : </th> + <th><?php $tmp = $stats->factureMoy(); $nb_formated = number_format($tmp["value"], 2, ',', ' '); echo $nb_formated; ?></th> </thead> <tbody> <tr>