-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmovie.php
152 lines (121 loc) · 4.36 KB
/
movie.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php require_once "./user/components/header.php";
$search = request('search');
// limit for a page
$limit = 4;
$page = request('page');
if ($page <= 0) {
$offset = 0;
$page = 1;
} elseif ($page == 1) {
$offset = 0;
$page = 1;
} elseif ($page > 1) {
// loop for setting the offset
$offset = ($page - 1) * $limit;
}
// get list of total movies in database
$total_movies = count(all('movie'));
if ($limit < $total_movies) {
// total pages
$total_pages = ceil(($total_movies / $limit));
// echo ("$total_movies movies found. Page $page of $total_pages");
// echo "$offset, $limit";
if ($page) {
$result = query("SELECT * FROM movie ORDER BY id DESC LIMIT $offset, $limit");
}
} else {
$result = query("SELECT * FROM movie ORDER BY id DESC LIMIT 1, $limit");
$total_pages = null;
}
// php code for searching movies
if (strlen($search) >= 3) {
$result = query("SELECT * FROM `movie` WHERE (`name` LIKE '%" . $search . "%') ");
if (empty($result)) {
// setError('No data found!!');
}
}
if (hasError()) : ?>
<div id="error" class="ml-4 alert alert-danger">
<?php echo getError(); ?>
</div>
<?php endif; ?>
<?php if (hasSuccess()) : ?>
<div id="success" class="ml-4 alert alert-success">
<?php echo getSuccess(); ?>
</div>
<?php endif; ?>
<?php
?>
<div class="container my-5">
<form action="" method="GET">
<div class="my-4 d-flex mx-auto align-items-center col-md-12">
<h1 class="font-weight-bold col-md-6">Movies</h1>
<div class="input-group justify-content-end">
<div class="form-outline">
<input name="search" type="search" id="form1" class="form-control" />
<label class="form-label" for="form1">Search</label>
</div>
<button type="submit" class="btn btn-primary">
<i class="fas fa-search"></i>
</button>
</div>
</div>
</form>
<!-- cards -->
<div class="container d-flex gap-4 flex-wrap justify-content-center">
<?php foreach ($result as $key) : ?>
<a href="./user/book.php?id=<?php echo $key['id']; ?>" class="card col-lg-2.5 hover-shadow border rounded">
<div class="">
<img src="./uploads/<?php echo $key['image']; ?>" class="img-fluid w-100 rounded" />
</div>
<div class="card-body " style="color: #4a4a4a;">
<h5 class="card-title"><?php echo $key['name'] ?></h5>
<p class="card-text text-muted">
<?php
$genres = where('genre_movie', 'movie_id', '=', $key['id']);
$total_genre = count($genres);
$i = 1;
foreach ($genres as $g) {
$genre = find('genre', $g['genre_id']);
echo $genre['name'];
if ($i < $total_genre) echo ", ";
$i++;
}
?>
</p>
</div>
</a>
<?php endforeach; ?>
</div>
<?php
if (empty($result)) {
echo '<h5 style="height:50vh;"> No result Found!!</h5>';
}
?>
<!-- cards -->
<!-- pagination starts -->
<?php if ($total_pages > 1 && !$search) : ?>
<div class="mt-5">
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-end">
<?php
// loop for pagination
for ($i = 1; $i <= $total_pages; $i++) {
if ($i == $page) {
echo '<li class="page-item active" onclick="event.preventDefault()"><a class="page-link" href="?page=' . $i . '">' . $i . '</a></li>';
} else {
echo '<li class="page-item"><a class="page-link" href="?page=' . $i . '">' . $i . '</a></li>';
}
}
?>
<!-- <li>
hello
</li> -->
</ul>
</nav>
</div>
<?php endif; ?>
<!-- pagination ends -->
</div>
<?php
require_once "./user/components/footer.php"; ?>