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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
<p>
<h3>Liste de livres</h3>
<!-- Connexion à la base de données -->
<table>
<thead>
<tr>
<th>Titre</th>
<th>Auteur</th>
<th>Éditeur</th>
<th>Langue</th>
<th>Mots clés</th>
</thead>
<?php
try
{
$bdd = new PDO('sqlite:metadata.db');
}
catch (Exception $e)
{
die('Erreur : ' . $e->getMessage());
}
?>
<?php
// Lecture de la table
$reponse = $bdd->query('
SELECT books.title, authors.name AS author, publishers.name AS publisher, languages.lang_code, tags.name AS tag
FROM books
JOIN books_authors_link
ON books.id = books_authors_link.book
JOIN authors
ON authors.id = books_authors_link.author
JOIN books_publishers_link
ON books.id = books_publishers_link.book
JOIN publishers
ON publishers.id = books_publishers_link.publisher
JOIN books_languages_link
ON books.id = books_languages_link.book
JOIN languages
ON languages.id = books_languages_link.lang_code
JOIN books_tags_link
ON books.id = books_tags_link.book
JOIN tags
ON tags.id = books_tags_link.tag
');
while ($donnees = $reponse->fetch())
{
echo '
<tr>
<td>
' . htmlspecialchars($donnees['title']) . '
</td>
<td>
' . htmlspecialchars($donnees['author']) . '
</td>
<td>
' . htmlspecialchars($donnees['publisher']) . '
</td>
<td>
' . htmlspecialchars($donnees['lang_code']) . '
</td>
<td>
' . htmlspecialchars($donnees['tag']) . '
</td>
</tr>
';
}
?>
</table>
</p> |
Partager