This repository has been archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoulets.php
69 lines (61 loc) · 1.72 KB
/
poulets.php
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
<?php
// Connexion à la base de données
require_once('includes/db.php');
require_once('includes/fonctions.php');
// Définition titre page
$titrePage = "Liste des adresses";
// Headers html: <head> + titres
include('parties/header.php');
// Liste des champs sur lesquels on peut trier
$champsTriables= ['id', 'id_ferme', 'race'];
// Test de $_GET
$ordreDeTri = testOrderBy($champsTriables, 'id_ferme', 'ASC');
// Champ et direction de tri par défaut
$ordreChamp = $ordreDeTri[0];
$ordreDirection = $ordreDeTri[1];
$sql = "SELECT * FROM poulets ORDER BY $ordreChamp $ordreDirection";
$resultats = mysqli_query($connection, $sql);
// if(!$resultats = mysqli_query($connection, $sql));
?>
<table class="table table-condensed table-striped table-hover">
<thead>
<tr>
<th>
id
<a href="?order=id&direction=ASC">+</a>
<a href="?order=id&direction=DESC">-</a>
</th>
<th>
race
<a href="?order=race&direction=ASC">+</a>
<a href="?order=race&direction=DESC">-</a>
</th>
<th>
id_ferme
<a href="?order=id_ferme&direction=ASC">+</a>
<a href="?order=id_ferme&direction=DESC">-</a>
</th>
</tr>
</thead>
<tbody>
<?php
if(mysqli_num_rows($resultats) === 0):
echo "<tr><td>Il n'y a pas d'enregistrements</td></tr>";
else:
// Affichage des lignes de résultat
while($ligne = mysqli_fetch_assoc($resultats)):
//var_dump($ligne);
?>
<tr>
<td><?= $ligne['id'] ?></td>
<td><?= $ligne['race'] ?></td>
<td><?= $ligne['id_ferme'] ?></td>
</tr>
<?php
endwhile;
endif;
?>
</tbody>
</table>
<?php
include ('parties/footer.php');