Category selection
This commit is contained in:
parent
7d5f2880dc
commit
f34033a55d
5 changed files with 36 additions and 5 deletions
|
@ -1,5 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
$category = 0;
|
||||||
|
if (isset($_GET["category"]) and $_GET["category"])
|
||||||
|
$category = htmlspecialchars($_GET["category"]);
|
||||||
|
|
||||||
require_once(PATH_MODELS.$page.".php");
|
require_once(PATH_MODELS.$page.".php");
|
||||||
|
|
||||||
if (isset($photos) and $photos)
|
if (isset($photos) and $photos)
|
||||||
|
|
|
@ -14,3 +14,5 @@ define("PHOTO_NOT_FOUND", "Identifiant de photo incorrect dans l'URL");
|
||||||
define("DESCRIPTION", "Description");
|
define("DESCRIPTION", "Description");
|
||||||
define("FILE_NAME", "Nom du fichier");
|
define("FILE_NAME", "Nom du fichier");
|
||||||
define("CATEGORY", "Catégorie");
|
define("CATEGORY", "Catégorie");
|
||||||
|
define("CATEGORY_SELECT", "Quelles photos souhaitez-vous afficher ?");
|
||||||
|
define("ALL_PHOTOS", "Toutes les photos");
|
||||||
|
|
|
@ -6,11 +6,23 @@ $bdd = getPDO();
|
||||||
|
|
||||||
if ($bdd instanceof PDO) {
|
if ($bdd instanceof PDO) {
|
||||||
try {
|
try {
|
||||||
|
$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 = $bdd->prepare("SELECT * FROM Photo");
|
||||||
$req->execute();
|
$req->execute();
|
||||||
|
}
|
||||||
|
|
||||||
$photos = $req->fetchAll();
|
$photos = $req->fetchAll();
|
||||||
$req->closeCursor();
|
$req->closeCursor();
|
||||||
|
|
||||||
|
$req = $bdd->prepare("SELECT * FROM Categorie");
|
||||||
|
$req->execute();
|
||||||
|
|
||||||
|
$categories = $req->fetchAll();
|
||||||
|
$req->closeCursor();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$alert = choixAlert("query");
|
$alert = choixAlert("query");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,23 @@
|
||||||
<?php require_once(PATH_VIEWS.'alert.php');?>
|
<?php require_once(PATH_VIEWS.'alert.php');?>
|
||||||
|
|
||||||
<!-- Début de la page -->
|
<!-- 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>
|
<h1><?= TITRE_PAGE_ACCUEIL_TOUS ?></h1>
|
||||||
|
|
||||||
<?php if(isset($photos) and $photos) {
|
<?php if(isset($photos) and $photos) { ?>
|
||||||
foreach ($photos as $photo) {?>
|
<?php foreach ($photos as $photo) {?>
|
||||||
<a href="index.php?page=photo&id=<?= $photo["photoId"] ?>"><img src="<?= PATH_IMAGES ?>/<?= $photo['nomFich'] ?>" alt="<?= $photo['description'] ?>"></a>
|
<a href="index.php?page=photo&id=<?= $photo["photoId"] ?>"><img src="<?= PATH_IMAGES ?>/<?= $photo['nomFich'] ?>" alt="<?= $photo['description'] ?>"></a>
|
||||||
<?php }
|
<?php }
|
||||||
} ?>
|
} ?>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?= CATEGORY ?></th>
|
<th><?= CATEGORY ?></th>
|
||||||
<th><?= $photo["nomCat"] ?></th>
|
<th><a href="index.php?category=<?= $photo["catId"] ?>"><?= $photo["nomCat"] ?></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in a new issue