1
0
Fork 0

Category selection

This commit is contained in:
Ethanell 2020-10-27 22:23:11 +01:00
parent 7d5f2880dc
commit f34033a55d
5 changed files with 36 additions and 5 deletions

View file

@ -1,5 +1,9 @@
<?php
$category = 0;
if (isset($_GET["category"]) and $_GET["category"])
$category = htmlspecialchars($_GET["category"]);
require_once(PATH_MODELS.$page.".php");
if (isset($photos) and $photos)

View file

@ -14,3 +14,5 @@ define("PHOTO_NOT_FOUND", "Identifiant de photo incorrect dans l'URL");
define("DESCRIPTION", "Description");
define("FILE_NAME", "Nom du fichier");
define("CATEGORY", "Catégorie");
define("CATEGORY_SELECT", "Quelles photos souhaitez-vous afficher ?");
define("ALL_PHOTOS", "Toutes les photos");

View file

@ -6,11 +6,23 @@ $bdd = getPDO();
if ($bdd instanceof PDO) {
try {
$req = $bdd->prepare("SELECT * FROM Photo");
$req->execute();
$req = null;
if ($category !== 0) {
$req = $bdd->prepare("SELECT * FROM Photo where catId = ?");
$req->execute(array($category));
} else {
$req = $bdd->prepare("SELECT * FROM Photo");
$req->execute();
}
$photos = $req->fetchAll();
$req->closeCursor();
$req = $bdd->prepare("SELECT * FROM Categorie");
$req->execute();
$categories = $req->fetchAll();
$req->closeCursor();
} catch (Exception $e) {
$alert = choixAlert("query");
}

View file

@ -7,10 +7,23 @@
<?php require_once(PATH_VIEWS.'alert.php');?>
<!-- Début de la page -->
<?php if (isset($categories) and $categories) { ?>
<form>
<label for="category"><?= CATEGORY_SELECT ?></label>
<select id="category" name="category">
<option value="0"><?= ALL_PHOTOS ?></option>
<?php foreach ($categories as $cat) { ?>
<option value="<?= $cat["catId"] ?>" <?= $cat["catId"] == $category ? "selected" : "" ?>><?= $cat["nomCat"] ?></option>
<?php } ?>
</select>
<input type="submit">
</form>
<?php } ?>
<h1><?= TITRE_PAGE_ACCUEIL_TOUS ?></h1>
<?php if(isset($photos) and $photos) {
foreach ($photos as $photo) {?>
<?php if(isset($photos) and $photos) { ?>
<?php foreach ($photos as $photo) {?>
<a href="index.php?page=photo&id=<?= $photo["photoId"] ?>"><img src="<?= PATH_IMAGES ?>/<?= $photo['nomFich'] ?>" alt="<?= $photo['description'] ?>"></a>
<?php }
} ?>

View file

@ -24,7 +24,7 @@
</tr>
<tr>
<th><?= CATEGORY ?></th>
<th><?= $photo["nomCat"] ?></th>
<th><a href="index.php?category=<?= $photo["catId"] ?>"><?= $photo["nomCat"] ?></a></th>
</tr>
</table>
</div>