-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
109 lines (93 loc) · 3.9 KB
/
search.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
103
104
105
106
107
108
109
<?php
include "layout/include/header.php";
?>
<!--End navbar -->
<?php
if (isset($_GET['search'])) {
$search = $_GET['search'];
$stmt = $con->prepare("SELECT * FROM books WHERE bookTitle LIKE '%$search%' OR bookAuthor LIKE '%$search%';");
$stmt->execute();
if ($stmt->rowCount() > 0) {
?>
<div class="search-info bg-secondary text-white p-2 mb-3">
<span>نتائج البحث عن: </span>
<span><?php echo $search;?></span>
</div>
<div class="row">
<?php
if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1;
}
$limit = 6;
$start = ($page - 1) * $limit;
$total_cat = $stmt->rowCount();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="col-md-6 col-lg-4">
<div class="card text-center">
<div class="img-cover">
<img src="uploads/bookCovers/<?php echo $row['bookCover']; ?>" alt="Book cover" class="card-img-top">
</div>
<div class="card-book">
<h4 class="card-title">
<a href="book.php?id=<?php echo $row['id'];?>&&category=<?php echo $row['bookCat'];?>"><?php echo $row['bookTitle']; ?></a>
</h4>
<p class="card-text"><?php echo mb_substr($row['bookContent'], 0, 150, "UTF-8"); ?></p>
<button class="custom-btn">
<a href="book.php?id=<?php echo $row['id'];?>&&category=<?php echo $row['bookCat'];?>">تحميل الكتاب</a>
</button>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
</div>
<!-- Start pagination -->
<?php
$total_pages = ceil($total_cat / $limit);
?>
<nav aria-label="Page navigation example">
<ul class="pagination">
<li class="page-item"><a class="page-link" href="search.php?search=<?php echo $search;?>&&page=<?php if (($page - 1) > 0) {
echo $page - 1;
} else {
echo 1;
}
?>">السابق</a></li>
<?php
for ($i = 1; $i <= $total_pages; $i++) {
?>
<li class="page-item"><a class="page-link" href="search.php?search=<?php echo $search;?>&&page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
<?php
}
?>
<li class="page-item"><a class="page-link" href="search.php?search=<?php echo $search;?>&&page=<?php
if (($page + 1) < $total_pages) {
echo $page + 1;
} elseif (($page + 1) >= $total_pages) {
echo $total_pages;
}
?>">التالي</a></li>
</ul>
</nav>
<!-- End pagination -->
<?php
}
else {
?>
<div class="alert alert-danger">للاسف لم يتم العثور على اسم الكتاب او الكاتب</div>
<?php
}
?>
<?php
include "layout/include/footer.php";
?>
<?php
}
?>