-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook.php
More file actions
32 lines (25 loc) · 1.03 KB
/
book.php
File metadata and controls
32 lines (25 loc) · 1.03 KB
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
<?php
// On va afficher le détail d'un livre en particulier
$id = $_GET['id'] ?? 0;
// Si ce n'est PAS un nombre OU id strictement égal à
if(!is_numeric($id) || $id == 0){
// On a rien a faire sur la page
exit("Il n'y a rien à voir ici !");
}
require_once('connect.php');
$stmt = $pdo->prepare('SELECT titre, annee_publication as annee, nom_auteur as nom, prenom_auteur as prenom FROM livres LEFT JOIN auteurs on fk_id_auteur=id_auteur WHERE id_livre= :id');
$stmt->execute(array(
'id' => $id
));
// $stmt = $pdo->prepare('SELECT titre, annee_publication as annee, nom_auteur as nom, prenom_auteur as prenom FROM livres LEFT JOIN auteurs on fk_id_auteur=id_auteur WHERE id_livre= ? AND annee_publication = ?');
// $stmt->execute(array(
// $id, '1987', "", "","", 312
// ));
// On récupère UN SEUL résultat
$book = $stmt->fetch(); // sous forme de tableau indexé
?>
<article>
<h1><?=$book['titre'] ?></h1>
<span>Publié en <?=$book['annee'] ?></span>
<p>Écrit par <?=$book['prenom'] ?> <?=$book['nom'] ?></p>
</article>