-
Notifications
You must be signed in to change notification settings - Fork 2
/
book.php
60 lines (51 loc) · 1.7 KB
/
book.php
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
<?php require('includes/init.php'); ?>
<?php
require_once('includes/sanitizer.php');
require_once('includes/dbconnect.php');
$id = '';
$result = null;
if ($_SERVER["REQUEST_METHOD"] === "GET") {
$id = sanitize_input($_GET["id"]);
if (!empty($id)) {
$sql = "SELECT `b`.`book_id` `book_id`, `isbn`, `title`, `author`, `category`, `edition`, `borrow_date`, `return_date`, `due_date`, `description`, `cover` FROM `books` `b` LEFT JOIN `borrows` `bw` ON `b`.`book_id` = `bw`.`book_id` WHERE `b`.`book_id` = $id";
$result = $conn->query($sql);
}
}
function show_book($result)
{
if ($result !== null && $result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
// var_dump($row);
$bookid = $row['book_id'];
$cover = $row['cover'];
$title = $row['title'];
$author = $row['author'];
$isbn = $row['isbn'];
$description = $row['description'];
$edition = $row['edition'];
$category = $row['category'];
$bookavailable = $row['borrow_date'] ? ($row['return_date'] ? (strtotime($row['return_date']) > strtotime($row['borrow_date']) ? true : false) : false) : true;
require('components/_bookdetails.php');
}
} else {
echo "<p>Book does not exist.</p>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<?php
require('includes/styles.php');
?>
</head>
<body>
<?php require('components/_header.php'); ?>
<?php require('components/_search.php'); ?>
<div class="spacer center">
<?php show_book($result); ?>
</div>
<?php require('components/_footer.php'); ?>
<script src="scripts/book.js"></script>
</body>
</html>