/
filter_results.php
86 lines (66 loc) · 2.1 KB
/
filter_results.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
<?php
include 'includes/functions.php';
include 'includes/mysqli_connect.php';
include 'includes/navbar.php';
include 'includes/login_check.php';
include 'includes/track_page_view.php';
$arr = array('mintime' => $_GET["runtime-min"],
'maxtime' => $_GET["runtime-max"],
'minyear' => str_replace('< ', '', $_GET["year-min"]),
'maxyear' => $_GET["year-max"],
'language' => $_GET["language"],
'genre' => $_GET["genre"],
'mpaa' => $_GET["mpaa"],
'orderby' => $_GET["orderby"]);
$i = 0;
$query = filter_query($arr, 'movies.id');
$total = $mysqli->query($query)->num_rows;
$page = 1;
if ($_GET['page']) {
$page = $_GET['page'];
$i = ($page - 1) * $numPerPage;
}
$searchlimit = min($total, $i + $numPerPage);
$ids = array();
if($s1 = $mysqli->query($query . " LIMIT $numPerPage OFFSET $i")) {
while($r1 = mysqli_fetch_assoc($s1)) {
$ids[] = $r1['id'];
}
}
$movies = getMoviesShort($ids);
gen_page_header('Filter Search Results | readyto.watch');
$navbarPage = 5;
include 'includes/left_navbar.php';
?>
<body>
<div id="container">
<?php
if ($total > 0) {
echo "Your search returned <b>" . (($total == 1) ? "1</b> result:" : "$total</b> results:")
. " showing " . (($total > $numPerPage) ? (($i == 0) ? "first $numPerPage movies." : "movies " . ($i + 1) . " - $searchlimit.") : "all $total movie".(($total == 1) ? ".":"s."));
?>
<p>Can't find the movie you were looking for? Return to <a href='search/filter'>the Filter Search</a>.</p>
<?php
foreach($movies as $movie) {
$params = $movie['params'];
$cast = $movie['actors'];
include 'templates/gen_entry.php';
}
//////////////////// PAGINATION //////////////////////
if ($total > $numPerPage) {
$url = gen_url($arr);
$num_pages = ceil($total/$numPerPage);
$current = $page;
$paginationUrl = "filter?$url&page=";
gen_pagination($current, $numPerPage, $num_pages, $paginationUrl);
}
} else {
echo '<br>Your search returned no results. <a href="search/filter">Try another search!</a><br><br>';
}
// close the connection
$mysqli->close();
?>
</div> <!-- #container -->
<?php
gen_page_footer();
?>