-
Notifications
You must be signed in to change notification settings - Fork 0
/
book-list.php
102 lines (87 loc) · 3.12 KB
/
book-list.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
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
<?php
require_once "config.php";
$db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($db->connect_errno) {
exit("Database connection failed: " . $db->connect_error . " (" . $db->connect_errno . ")");
}
?>
<?php
$sql = "SELECT * FROM tbl_94_books ORDER BY name";
$res = $db->query($sql);
if(!$res) {
exit("Database query failed.");
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<script src="includes/getbookslist.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>books list</title>
</head>
<body>
<header id="header" class="page-header">
<div class="page-header row">
<!-- Logo -->
<div class="col-md-4">
<a href="#" class="logo"><span> Flourish </span>&<span> Blotts </span></a>
</div>
<div class="col-md-4 col-md-offset-4">
<!-- Search -->
<div class="catalog-search">
<input class="shuffle-search input_field " type="search" autocomplete="off" value="" maxlength="128" placeholder="Search Book" id="input-search"/>
<button type="button" name="button" id='clickMe'><i class="fa fa-search" aria-hidden="true"></i></button>
</div>
</div>
</div>
</header>
<main>
<div class="filter-dropdown">
<label class="category-list" for="category-select">Filter by Category:</label>
<select id="category-select">
<option value="all">All</option>
<?php
foreach ($categories['category'] as $category) {
echo '<option value="' . $category['name'] . '">' . $category['name'] . '</option>';
}
?>
</select>
</div>
<?php
if ($res->num_rows > 0) {
$outputBooks = '<div class="rows" id="books">';
while ($data = $res->fetch_assoc()) {
$bookId = $data['id'];
$bookName = $data['name'];
$bookDescription = $data['description'];
$bookPrice = $data['price'];
$bookAuthor = $data['author'];
$bookImage = $data['photo'];
$bookCategory = $data['category'];
$bookCol = '<div class="col-md-6" id="books-img-info' . $bookId . '" data-category="' . $bookCategory . '">';
$bookCol .= '<div class="book-image"><img src="' . $bookImage . '"/></div>';
$bookCol .= '<div class="book-info" id="book-info">';
$bookCol .= '<h3>' . $bookName . '</h3><p class="author">by ' . $bookAuthor . '</p>';
$bookCol .= '<p class="description">' . $bookDescription . '</p>';
if (!empty($bookPrice)) {
$bookCol .= '<p class="price">Price: ' . $bookPrice . '$</p>';
}
$bookCol .= '<a href="book.php?id=' . $bookId . '" class="view">View Details</a></div></div>';
$outputBooks .= $bookCol;
}
$outputBooks .= '</div>';
echo '<div class="container" id="title"></div>';
echo $outputBooks;
echo '<br>';
} else {
echo "No data found.";
}
?>
</main>
</body>
</html>
<?php
$db->close();
?>