Visa Källkod

The following files exist in this folder. Click to view.

NamnTypStorlek
account.phpPHP Fil11.6 KB
admin.phpPHP Fil23.6 KB
authors.phpPHP Fil4.1 KB
book.phpPHP Fil5.9 KB
db_cnnt.phpPHP Fil407 B
header.phpPHP Fil1.7 KB
home.phpPHP Fil8.4 KB
index.phpPHP Fil5.3 KB
loan_handler.phpPHP Fil1.9 KB
manage_authors.phpPHP Fil4.7 KB
my_loans.phpPHP Fil6.9 KB
S.sqlSQL Fil3.3 KB
search.phpPHP Fil11 KB

authors.php

125 lines UTF-8 Unix (LF) - Type: PHP Fil
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php

include 'header.php';
require_once 
'db_cnnt.php';
global 
$pdo;

// Kolla om vi ska visa en specifik författare
$author_id = (int)($_GET['id'] ?? 0);

if (
$author_id 0) {
    
// Visa detaljer om en viss författare
    
$statement $pdo->prepare("SELECT * FROM författare WHERE författare_id = ?");
    
$statement->execute([$author_id]);
    
$author $statement->fetch();
    
    
// Om författaren inte finns, tillbaka till listan
    
if (!$author) {
        
header('Location: authors.php');
        exit;
    }
    
    
// Hämta alla böcker av denna författare
    
$statement $pdo->prepare("SELECT b.bok_id, b.titel, g.namn AS genre, s.namn AS språk, b.isbn, b.cover_url 
        FROM bok b 
        LEFT JOIN genre g ON b.genre_id = g.genre_id 
        LEFT JOIN språk s ON b.språk_id = s.språk_id 
        WHERE b.författare_id = ? 
        ORDER BY b.titel"
);
    
$statement->execute([$author_id]);
    
$books $statement->fetchAll();
    
?>
    <!DOCTYPE html>
    <html lang="sv">
    <head>
        <meta charset="UTF-8">
        <title><?= htmlspecialchars($author['namn']) ?> - Författare</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
    <div class="container">
        <h1><?= htmlspecialchars($author['namn']) ?></h1>
        <?php if (!empty($author['bio'])): ?>
            <div class="author-bio">
                <h3>Biografi</h3>
                <p><?= nl2br(htmlspecialchars($author['bio'])) ?></p>
            </div>
        <?php endif; ?>
        
        <h2>Böcker av <?= htmlspecialchars($author['namn']) ?></h2>
        <table>
            <thead>
                <tr>
                    <th>Omslag</th>
                    <th>Titel</th>
                    <th>Genre</th>
                    <th>Språk</th>
                    <th>ISBN</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($books as $book): ?>
                    <tr>
                        <td>
                            <?php if (!empty($book['cover_url'])): ?>
                                <img src="<?= htmlspecialchars($book['cover_url']) ?>" alt="Omslag" class="book-cover">
                            <?php endif; ?>
                        </td>
                        <td><?= htmlspecialchars($book['titel']) ?></td>
                        <td><?= htmlspecialchars($book['genre']) ?></td>
                        <td><?= htmlspecialchars($book['språk']) ?></td>
                        <td><?= htmlspecialchars($book['isbn']) ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <a href="authors.php" class="btn-back">Tillbaka till alla författare</a>
    </div>
    </body>
    </html>
    <?php
} else {
    
// OM ingen specifik författare vald - visa alla
    
$statement $pdo->query("SELECT f.författare_id, f.namn, COUNT(b.bok_id) as antal_böcker 
        FROM författare f 
        LEFT JOIN bok b ON f.författare_id = b.författare_id 
        GROUP BY f.författare_id 
        ORDER BY f.namn"
);
    
$authors $statement->fetchAll();
    
?>
    <!DOCTYPE html>
    <html lang="sv">
    <head>
        <meta charset="UTF-8">
        <title>Författare</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
    <div class="container">
        <h1>Författare</h1>
        <table>
            <thead>
                <tr>
                    <th>Författare</th>
                    <th>Antal böcker</th>
                    <th>Åtgärd</th>
                </tr>
            </thead>
            <tbody>
                <!--loop for authors as author-->
                <?php foreach ($authors as $author): ?>
                    <tr>
                        <td><?= htmlspecialchars($author['namn']) ?></td>
                        <td><?= $author['antal_böcker'?></td>
                        <td><a href="authors.php?id=<?= $author['författare_id'?>">Visa böcker →</a></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    </body>
    </html>
    <?php
}
?>