animaux.php 1.65 KB
Newer Older
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<html>
<head>
  <title>Exercice</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" type="text/css" href="style.css">
  </head>
<body>
  <h1>Information des animaux</h1>
  <table border="1">
    <tr>
      <th>idAnimal</th>
      <th>Nom</th>
      <th>Poids</th>
      <th>Taille</th>
      <th>Naissance</th>
      <th>idClient</th>
      <th>Espece</th>
      <th>Statistiques</th>
      <th>Supprimer</th>
    </tr>
    <?php
    // Connexion à la base de données
Gaetan Carabetta's avatar
Gaetan Carabetta committed
23
    include("connexion.php");
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
24
25
26
27

    try{
      $vConn = new PDO("pgsql:host=$vHost;port=$vPort;dbname=$vData", $vUser, $vPass);
    } catch(PDOException $e){
Gaetan Carabetta's avatar
Gaetan Carabetta committed
28
      echo "Erreur de connexion '$e'";
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
29
30
31
32
33
34
35
    }

    // Affichage du tableau de données
    try{
      $vSt = $vConn->prepare($vSql);
      $vSt->execute();

Gaetan Carabetta's avatar
Gaetan Carabetta committed
36
      
Osvaldo Valdivia Salas's avatar
Osvaldo Valdivia Salas committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
      while ($vResult = $vSt->fetch(PDO::FETCH_BOTH)) {
        echo '<tr>';
        echo "<td>$vResult[0]</td>";
        echo "<td>$vResult[1]</td>";
        echo "<td>$vResult[2]</td>";
        echo "<td>$vResult[3]</td>";
        echo "<td>$vResult[4]</td>";
        echo "<td>$vResult[5]</td>";
        echo "<td>$vResult[6]</td>";
        echo "<td><form action='statAnimal.php' method='post'> <input type='text' name='idAnimal' value=$vResult[0] hidden/> <input  type='submit' value='Statistiques'> </form></td>";
        echo "<td><form action='remAnimal.php' method='post'> <input type='text' name='idAnimal' value=$vResult[0] hidden/> <input id='btnRemove' type='submit' value='X'> </form></td>";
        echo '</tr>';
      }

    } catch(PDOException $e){
      echo "Erreur de requete '$e'";
    }
    ?>

  </table>
</body>
</html>