-
Notifications
You must be signed in to change notification settings - Fork 3
/
category_list.php
49 lines (47 loc) · 1.17 KB
/
category_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
<?php
session_start();
require_once "./functions/database_functions.php";
$conn = db_connect();
$query = "SELECT * FROM category ORDER BY category_name";
$result = mysqli_query($conn, $query);
if(!$result){
echo "Can't retrieve data " . mysqli_error($conn);
exit;
}
if(mysqli_num_rows($result) == 0){
echo "Empty category ! Something wrong! check again";
exit;
}
$title = "List Of Categories";
require "./template/header.php";
?>
<p class="lead">List of Category</p>
<ul>
<?php
while($row = mysqli_fetch_assoc($result)){
$count = 0;
$query = "SELECT categoryid FROM books";
$result2 = mysqli_query($conn, $query);
if(!$result2){
echo "Can't retrieve data " . mysqli_error($conn);
exit;
}
while ($pubInBook = mysqli_fetch_assoc($result2)){
if($pubInBook['categoryid'] == $row['categoryid']){
$count++;
}
}
?>
<li>
<span class="badge"><?php echo $count; ?></span>
<a href="bookPerCat.php?catid=<?php echo $row['categoryid']; ?>"><?php echo $row['category_name']; ?></a>
</li>
<?php } ?>
<li>
<a href="books.php">List full of books</a>
</li>
</ul>
<?php
mysqli_close($conn);
require "./template/footer.php";
?>