-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
88 lines (79 loc) · 3.27 KB
/
index.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
<?php
$TITLE = "Welcome -- Bookstore Inc";
require_once "templates/header.html.php";
// Prevent showing mysql errors
//error_reporting(0);
$connection->select_db("bookstore");
$query = "SELECT isbn,name,author,picture,price,detail FROM book";
if (isset($_GET["new-releases"]))
$query = $query . " ORDER BY date_added DESC";
$books = $connection->query($query);
$tags = null;
if ($books->num_rows === 0) {
echo "0 books found";
} else {
$tag_query = "SELECT tag,COUNT(isbn) AS count FROM is_tagged GROUP BY tag ORDER BY count DESC LIMIT 6";
$tags = $connection->query($tag_query);
$bestseller_query = "SELECT book, COUNT(book) AS count FROM sales.books_bill GROUP BY book ORDER BY count DESC LIMIT 6";
$bestsellers = $connection->query($bestseller_query);
}
?>
<div id="content">
<div id="content_left">
<div class="content_left_section">
<h1>Categories</h1>
<ul>
<?php
while ($tag = $tags->fetch_assoc()) {
echo "<li><a href='tag.php?tag={$tag['tag']}'>{$tag['tag']}</a>";
}
?>
</ul>
</div>
<div class="content_left_section">
<h1>Bestsellers</h1>
<ul>
<?php
$isbn = null;
$bestseller_name = null;
$book_query = $connection->prepare("SELECT name FROM book WHERE isbn = ?");
$book_query->bind_param("i", $isbn);
$book_query->bind_result($bestseller_name);
while ($bestseller = $bestsellers->fetch_assoc()) {
$isbn = $bestseller["book"];
$book_query->execute();
$book_query->fetch();
echo "<li><a href='details.php?isbn={$isbn}'>{$bestseller_name}</a></li>";
}
?>
</ul>
</div>
</div> <!-- end of content left -->
<div id="content_right">
<?php
$count = 1;
while ($book = $books->fetch_assoc()) {
?>
<div class="product_box">
<h1><?php echo $book["name"]; ?> <span>(by <?php echo $book["author"]; ?>)</span></h1>
<img src="<?php echo $book["picture"] ?>" alt="book picture" height="125px" width="100px"/>
<div class="product_info">
<p><?php echo substr($book["detail"], 0, 50); ?>...<a href="/details.php?isbn=<?php echo $book["isbn"]; ?>">More</a></p>
<div class="buy_now_button" id="<?php echo $book["isbn"]; ?>"><a href="/cart.php?book=<?php echo $book["isbn"]; ?>">Add to cart - Rs <?php echo $book["price"]; ?></a></div>
<div class="detail_button"><a href="/details.php?isbn=<?php echo $book["isbn"]; ?>">Detail</a></div>
</div>
<div class="cleaner"> </div>
</div>
<?php
if (($count % 2) == 1)
echo "<div class=\"cleaner_with_width\"> </div>";
else
echo "<div class=\"cleaner_with_height\"> </div>";
$count++;
}
?>
<div class="cleaner_with_height"> </div>
</div>
<?php
require_once "templates/footer.html.php";
?>