statAnimal.php 2.04 KB
Newer Older
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
1
2
<html>
<head>
Gaetan Carabetta's avatar
Gaetan Carabetta committed
3
  <title>Clinique Vétérinaire</title>
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
4
5
6
7
8
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href="style.css">
  </head>
<body>
  <?php
Gaetan Carabetta's avatar
Gaetan Carabetta committed
9
    include("connexion.php");
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
10
11
12
    try{
      $vConn = new PDO("pgsql:host=$vHost;port=$vPort;dbname=$vData", $vUser, $vPass);
    } catch(PDOException $e){
Gaetan Carabetta's avatar
Gaetan Carabetta committed
13
      echo "Erreur de connexion '$e'";
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
14
15
16
17
    }
    $idAnimal = $_POST['idAnimal'];

    if($idAnimal == ""){
Gaetan Carabetta's avatar
Gaetan Carabetta committed
18
        echo "Il faut sélectionner un animal";
Gaetan Carabetta's avatar
Gaetan Carabetta committed
19
        header('Location: http://tuxa.sme.utc/~bdd0p042/application/animaux.php');
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
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
      }
  ?>

  <h1>Quantité de médicament prescrite à un animal</h1>
  <table border="1">
    <tr>
      <th>Medicament</th>
      <th>Somme</th>
    </tr>
    <?php

    try{
      $vSql ="SELECT P.nomMolec as medicament, COUNT(*) as quantite_prescrite
        FROM Posologie P JOIN Traitement T on P.traitement=T.idTraitement
        WHERE T.idAnimal=' $idAnimal'
        GROUP BY P.nomMolec;
      ";


      $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>


Gaetan Carabetta's avatar
Gaetan Carabetta committed
54
  <h1>Nombre de comprimés prescrit à un animal </h1>
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
55
56
57
  <table border="1">
    <tr>
      <th>Medicament</th>
Gaetan Carabetta's avatar
Gaetan Carabetta committed
58
      <th>Nb comprimés</th>
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
59
60
61
62
    </tr>
    <?php

    try{
Gaetan Carabetta's avatar
Gaetan Carabetta committed
63
        $vSql ="SELECT P.nomMolec, SUM(P.duree*P.nbJourna) FROM Posologie P
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
          JOIN Traitement T ON P.traitement=T.idTraitement WHERE
          T.idAnimal='$idAnimal'  group by P.nomMolec;
        ";


        $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>