statEspece.php 1.87 KB
Newer Older
Gaetan Carabetta's avatar
Gaetan Carabetta committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<html>
<head>
  <title>Clinique Vétérinaire</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href="style.css">
  </head>
<body>
  <?php
    include("connexion.php");
    try{
      $vConn = new PDO("pgsql:host=$vHost;port=$vPort;dbname=$vData", $vUser, $vPass);
    } catch(PDOException $e){
      echo "Erreur de connexion '$e'";
    }
    $espece = $_POST['espece'];

    if($espece == ""){
        echo "Il faut sélectionner une espece";
        header('Location: http://tuxa.sme.utc/~bdd0p042/application/especes.php');
      }
  ?>

    <h1>Poids moyen des <?php echo $espece ?></h1>
  <table border="1">
    <tr>
      <th>Espèce</th>
      <th>Poids moyen</th>
    </tr>
    <?php

    try{
      $vSql ="SELECT A.especenom, AVG(A.poids)
        FROM Animal A
        WHERE A.especenom = '$espece'
        GROUP BY A.especenom;
      ";


      $vSt = $vConn->prepare($vSql);
      $vSt->execute();
      while ($vResult = $vSt->fetch(PDO::FETCH_BOTH)) {
        echo '<tr>';
        echo "<td>$vResult[0]</td>";
        echo "<td>$vResult[1]</td>";
        echo '</tr>';
      }
    } catch(PDOException $e){
      echo "Erreur de requete '$e'";
    }
    ?>
  </table>

  <h1>Taille moyenne des <?php echo $espece ?></h1>
  <table border="1">
    <tr>
      <th>Espèce</th>
      <th>Taille moyenne</th>
    </tr>
    <?php

    try{
      $vSql ="SELECT A.especenom, AVG(A.taille)
        FROM Animal A
        WHERE A.especenom = $espece
        GROUP BY A.especenom;
      ";


      $vSt = $vConn->prepare($vSql);
      $vSt->execute();
      while ($vResult = $vSt->fetch(PDO::FETCH_BOTH)) {
        echo '<tr>';
        echo "<td>$vResult[0]</td>";
        echo "<td>$vResult[1]</td>";
        echo '</tr>';
      }
    } catch(PDOException $e){
      echo "Erreur de requete '$e'";
    }
    ?>
  </table>
</body>
</html>