Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pagination Function
- function pagination($query,$per_page=10,$page=1,$url='?'){
- global $conDB;
- $query = "SELECT COUNT(*) as `num` FROM movies";
- $row = mysqli_fetch_array(mysqli_query($conDB,$query));
- $total = $row['num'];
- $adjacents = "2";
- $prevlabel = "‹ Prev";
- $nextlabel = "Next ›";
- $lastlabel = "Last ››";
- $page = ($page == 0 ? 1 : $page);
- $start = ($page - 1) * $per_page;
- $prev = $page - 1;
- $next = $page + 1;
- $lastpage = round($total/$per_page);
- $lpm1 = $lastpage - 1; // //last page minus 1
- $pagination = "";
- if($lastpage > 1){
- $pagination .= "<ul class='pagination'>";
- if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>
- {$prevlabel}</a></li>";
- if ($lastpage < 7 + ($adjacents * 2)){
- for ($counter = 1; $counter <= $lastpage; $counter++){
- if ($counter == $page)
- $pagination.= "<li><a class='current'>{$counter}</a>
- </li>";
- else
- $pagination.= "<li><a href='{$url}page={$counter}'>
- {$counter}</a></li>";
- }
- } elseif($lastpage > 5 + ($adjacents * 2)){
- if($page < 1 + ($adjacents * 2)) {
- for ($counter = 1; $counter < 4 + ($adjacents * 2);
- $counter++){
- if ($counter == $page)
- $pagination.= "<li><a class='current'>{$counter}
- </a></li>";
- else
- $pagination.= "<li><a href='{$url}page={$counter}'>
- {$counter}</a></li>";
- }
- $pagination.= "<li class='dot'>...</li>";
- $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a>
- </li>";
- $pagination.= "<li><a href='{$url}page={$lastpage}'>
- {$lastpage}</a></li>";
- } elseif($lastpage - ($adjacents * 2) > $page && $page >
- ($adjacents * 2)) {
- $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
- $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
- $pagination.= "<li class='dot'>...</li>";
- for ($counter = $page - $adjacents; $counter <= $page +
- $adjacents; $counter++) {
- if ($counter == $page)
- $pagination.= "<li><a class='current'>{$counter}
- </a></li>";
- else
- $pagination.= "<li><a href='{$url}page={$counter}'>
- {$counter}</a></li>";
- }
- $pagination.= "<li class='dot'>..</li>";
- $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a>
- </li>";
- $pagination.= "<li><a href='{$url}page={$lastpage}'>
- {$lastpage}</a></li>";
- } else {
- $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
- $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
- $pagination.= "<li class='dot'>..</li>";
- for ($counter = $lastpage - (2 + ($adjacents * 2));
- $counter <= $lastpage; $counter++) {
- if ($counter == $page)
- $pagination.= "<li><a class='current'>{$counter}
- </a></li>";
- else
- $pagination.= "<li><a href='{$url}page={$counter}'>
- {$counter}</a></li>";
- }
- }
- }
- if ($page < $counter - 1) {
- $pagination.= "<li><a href='{$url}page={$next}'>{$nextlabel}</a>
- </li>";
- $pagination.= "<li><a href='{$url}page=$lastpage'>{$lastlabel}</a>
- </li>";
- }
- $pagination.= "</ul>";
- }
- return $pagination;
- }//
- $page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]);
- if ($page <= 0) $page = 1;
- $per_page = 2; // Set how many records do you want to display per page.
- $startpoint = ($page * $per_page) - $per_page;
- $statement = "`movies` ORDER BY `m_id` ASC"; name.
- $con = mysqli_connect("localhost","root","","blabla");
- $mysqli = new mysqli("localhost", "root", "", "blabla");
- $db_username = 'root';
- $db_password = '';
- $db_name = 'blabla'; .
- $db_host = 'localhost';
- $conDB = mysqli_connect($db_host, $db_username,
- $db_password,$db_name)or die('Error: Could not connect to
- database.');
- if (mysqli_connect_errno())
- {
- echo "Failed to Connect to MySQL:" . mysqli_connect_error();
- }
- $results2 = $mysqli->query( "select distinct(m_genre)
- from movies where movie_status = '1'");
- while($genre_data = mysqli_fetch_assoc($results2)){
- ?>
- <a href="javascript:void(0);" class="list-group-item">
- <label>
- <input type="checkbox" class="item_filter genre"
- value="<?php echo $genre_data['m_genre']; ?>" <?php
- if(in_array($genre_data['m_genre'],$genre)){ echo"checked";
- } ?> >
- <span class="check-box-effect"></span>
- <?php echo $genre_data['m_genre']; ?>
- </label></a>
- <?php } ?>
- </div>
- <div class="col-xs-4">
- <h3>Country</h3>
- <?php
- $rs = $mysqli->query("select distinct(m_country)
- from movies where movie_status = '1'");
- while($country_data = mysqli_fetch_assoc($rs)){
- ?>
- <a href="javascript:void(0);" class="list-group-item">
- <input type="checkbox" class="item_filter country"
- value="<?php echo $country_data['m_country']; ?>" <?php
- if(in_array($country_data['m_country'],$country)){
- echo"checked"; } ?> >
- <?php echo $country_data['m_country'];
- ?> </a>
- <?php } ?>
- </div>
- <div class="col-xs-4">
- <h3>Year</h3>
- <?php
- $rs = $mysqli->query( "select distinct(m_year)
- from movies where movie_status = '1'");
- while($year_data = mysqli_fetch_assoc($rs)){
- ?>
- <a href="javascript:void(0);" class="list-group-item">
- <input type="checkbox" class="item_filter year"
- value=" <?php echo $year_data['m_year']; ?>"
- <?php if(in_array($year_data['m_year'],$year))
- { echo"checked"; } ?> >
- <?php echo $year_data['m_year']; ?></a>
- <?php } ?>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-xs-12">
- <?php
- $query = "SELECT * FROM movies
- WHERE movie_status = '1' ";
- //filter query start
- if(!empty($genre)){
- $genredata =implode("','",$genre);
- $query .= " and m_genre in('$genredata')LIMIT
- {$startpoint} , {$per_page} ";
- }
- if(!empty($country)){
- $countrydata =implode("','",$country);
- $query .= " and m_country
- in('$countrydata')LIMIT {$startpoint} , {$per_page} ";
- }
- if(!empty($year)){
- $yeardata =implode("','",$year);
- $query .= " and m_year in('$yeardata')LIMIT
- {$startpoint} , {$per_page} ";
- }
- //filter query end
- $rs = mysqli_query($mysqli,$query) or die("Error :
- ".mysqli_error($mysqli));
- echo '<div class= "wrap">';
- // displaying paginaiton.
- echo pagination($statement,$per_page,$page,$url='?');
- echo "</div>";
Add Comment
Please, Sign In to add comment