Files
TP3_PHP_BUT1/TP3/code/vues/vueFilms.php

92 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2025-05-21 07:43:45 +02:00
<!--
Variables de la vue
$films : les films de la page
$realisateurs : liste des réalisateurs
$realisateur_selectionne : ID du réalisateur sélectionné
$tri_actuel : critère de tri actuel
$nombreTotal : nombre total de films
-->
<h2>Films</h2>
<!-- Formulaire de filtrage par réalisateur -->
<form method="GET" action="films.php" style="margin-bottom: 20px;">
<label for="realisateur">Filtrer par réalisateur :</label>
<select name="realisateur" id="realisateur" onchange="this.form.submit()">
<option value="">-- Tous les réalisateurs --</option>
<?php foreach($realisateurs as $realisateur): ?>
2025-05-21 07:52:18 +02:00
<option value="<?= $realisateur['idArtiste'] ?>"
<?= ($realisateur_selectionne == $realisateur['idArtiste']) ? 'selected' : '' ?>>
2025-05-21 07:43:45 +02:00
<?= htmlspecialchars($realisateur['prenom'] . ' ' . $realisateur['nom']) ?>
</option>
<?php endforeach; ?>
</select>
<!-- Maintenir les autres paramètres -->
<input type="hidden" name="tri" value="<?= htmlspecialchars($tri_actuel) ?>">
</form>
<!-- Liens de tri -->
<div style="margin-bottom: 15px;">
<strong>Trier par :</strong>
<?php
$url_base = "films.php?";
if ($realisateur_selectionne) {
$url_base .= "realisateur=" . $realisateur_selectionne . "&";
}
?>
<a href="<?= $url_base ?>tri=titre" <?= ($tri_actuel == 'titre') ? 'style="font-weight: bold;"' : '' ?>>Titre</a> |
<a href="<?= $url_base ?>tri=annee" <?= ($tri_actuel == 'annee') ? 'style="font-weight: bold;"' : '' ?>>Année</a> |
<a href="<?= $url_base ?>tri=genre" <?= ($tri_actuel == 'genre') ? 'style="font-weight: bold;"' : '' ?>>Genre</a> |
<a href="<?= $url_base ?>tri=nom" <?= ($tri_actuel == 'nom') ? 'style="font-weight: bold;"' : '' ?>>Réalisateur</a>
</div>
<!-- Affichage du nombre de résultats -->
<p><em><?= count($films) ?> film(s) affiché(s) sur <?= $nombreTotal ?> au total</em></p>
<!-- Tableau des films -->
<table border="1" cellpadding="8" cellspacing="0" style="border-collapse: collapse; width: 100%;">
<thead>
<tr style="background-color: #f0f0f0;">
<th>Titre</th>
<th>Année</th>
<th>Genre</th>
<th>Réalisateur</th>
</tr>
</thead>
<tbody>
<?php if (empty($films)): ?>
<tr>
<td colspan="4" style="text-align: center; font-style: italic;">Aucun film trouvé</td>
</tr>
<?php else: ?>
<?php foreach($films as $film): ?>
<tr>
<td>
<a href="./fiche.php?film=<?= $film['idFilm'] ?>" style="text-decoration: none; color: #0066cc;">
<?= htmlspecialchars($film['titre']) ?>
</a>
</td>
<td><?= htmlspecialchars($film['annee']) ?></td>
<td><?= htmlspecialchars($film['genre']) ?></td>
<td><?= htmlspecialchars($film['prenom'] . ' ' . $film['nom']) ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<!-- Exemple de limitation avec LIMIT -->
<div style="margin-top: 20px;">
<strong>Affichage limité :</strong>
<?php
$url_limit = "films.php?";
if ($realisateur_selectionne) {
$url_limit .= "realisateur=" . $realisateur_selectionne . "&";
}
$url_limit .= "tri=" . $tri_actuel . "&";
?>
<a href="<?= $url_limit ?>limit=5">5 premiers</a> |
<a href="<?= $url_limit ?>limit=10">10 premiers</a> |
<a href="<?= $url_limit ?>">Tous</a>
</div>