Guest User

Untitled

a guest
Nov 9th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. // Pagination Function
  2. function pagination($query,$per_page=10,$page=1,$url='?'){
  3. global $conDB;
  4. $query = "SELECT COUNT(*) as `num` FROM movies";
  5. $row = mysqli_fetch_array(mysqli_query($conDB,$query));
  6. $total = $row['num'];
  7. $adjacents = "2";
  8.  
  9. $prevlabel = "‹ Prev";
  10. $nextlabel = "Next ›";
  11. $lastlabel = "Last ››";
  12.  
  13. $page = ($page == 0 ? 1 : $page);
  14. $start = ($page - 1) * $per_page;
  15.  
  16. $prev = $page - 1;
  17. $next = $page + 1;
  18.  
  19. $lastpage = round($total/$per_page);
  20.  
  21. $lpm1 = $lastpage - 1; // //last page minus 1
  22.  
  23. $pagination = "";
  24. if($lastpage > 1){
  25. $pagination .= "<ul class='pagination'>";
  26.  
  27.  
  28. if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>
  29. {$prevlabel}</a></li>";
  30.  
  31. if ($lastpage < 7 + ($adjacents * 2)){
  32. for ($counter = 1; $counter <= $lastpage; $counter++){
  33. if ($counter == $page)
  34. $pagination.= "<li><a class='current'>{$counter}</a>
  35. </li>";
  36. else
  37. $pagination.= "<li><a href='{$url}page={$counter}'>
  38. {$counter}</a></li>";
  39. }
  40.  
  41. } elseif($lastpage > 5 + ($adjacents * 2)){
  42.  
  43. if($page < 1 + ($adjacents * 2)) {
  44.  
  45. for ($counter = 1; $counter < 4 + ($adjacents * 2);
  46. $counter++){
  47. if ($counter == $page)
  48. $pagination.= "<li><a class='current'>{$counter}
  49. </a></li>";
  50. else
  51. $pagination.= "<li><a href='{$url}page={$counter}'>
  52. {$counter}</a></li>";
  53. }
  54. $pagination.= "<li class='dot'>...</li>";
  55. $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a>
  56. </li>";
  57. $pagination.= "<li><a href='{$url}page={$lastpage}'>
  58. {$lastpage}</a></li>";
  59.  
  60. } elseif($lastpage - ($adjacents * 2) > $page && $page >
  61. ($adjacents * 2)) {
  62.  
  63. $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
  64. $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
  65. $pagination.= "<li class='dot'>...</li>";
  66. for ($counter = $page - $adjacents; $counter <= $page +
  67. $adjacents; $counter++) {
  68. if ($counter == $page)
  69. $pagination.= "<li><a class='current'>{$counter}
  70. </a></li>";
  71. else
  72. $pagination.= "<li><a href='{$url}page={$counter}'>
  73. {$counter}</a></li>";
  74. }
  75. $pagination.= "<li class='dot'>..</li>";
  76. $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a>
  77. </li>";
  78. $pagination.= "<li><a href='{$url}page={$lastpage}'>
  79. {$lastpage}</a></li>";
  80.  
  81. } else {
  82.  
  83. $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
  84. $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
  85. $pagination.= "<li class='dot'>..</li>";
  86. for ($counter = $lastpage - (2 + ($adjacents * 2));
  87. $counter <= $lastpage; $counter++) {
  88. if ($counter == $page)
  89. $pagination.= "<li><a class='current'>{$counter}
  90. </a></li>";
  91. else
  92. $pagination.= "<li><a href='{$url}page={$counter}'>
  93. {$counter}</a></li>";
  94. }
  95. }
  96. }
  97.  
  98. if ($page < $counter - 1) {
  99. $pagination.= "<li><a href='{$url}page={$next}'>{$nextlabel}</a>
  100. </li>";
  101. $pagination.= "<li><a href='{$url}page=$lastpage'>{$lastlabel}</a>
  102. </li>";
  103. }
  104.  
  105. $pagination.= "</ul>";
  106. }
  107.  
  108. return $pagination;
  109. }//
  110.  
  111. $page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]);
  112. if ($page <= 0) $page = 1;
  113.  
  114. $per_page = 2; // Set how many records do you want to display per page.
  115.  
  116. $startpoint = ($page * $per_page) - $per_page;
  117.  
  118. $statement = "`movies` ORDER BY `m_id` ASC"; name.
  119.  
  120. $con = mysqli_connect("localhost","root","","blabla");
  121. $mysqli = new mysqli("localhost", "root", "", "blabla");
  122.  
  123.  
  124. $db_username = 'root';
  125. $db_password = '';
  126. $db_name = 'blabla'; .
  127. $db_host = 'localhost';
  128.  
  129. $conDB = mysqli_connect($db_host, $db_username,
  130. $db_password,$db_name)or die('Error: Could not connect to
  131. database.');
  132.  
  133.  
  134. if (mysqli_connect_errno())
  135. {
  136.  
  137. echo "Failed to Connect to MySQL:" . mysqli_connect_error();
  138. }
  139.  
  140.  
  141. $results2 = $mysqli->query( "select distinct(m_genre)
  142. from movies where movie_status = '1'");
  143.  
  144. while($genre_data = mysqli_fetch_assoc($results2)){
  145.  
  146. ?>
  147.  
  148. <a href="javascript:void(0);" class="list-group-item">
  149. <label>
  150. <input type="checkbox" class="item_filter genre"
  151. value="<?php echo $genre_data['m_genre']; ?>" <?php
  152. if(in_array($genre_data['m_genre'],$genre)){ echo"checked";
  153. } ?> >
  154. <span class="check-box-effect"></span>
  155. &nbsp;&nbsp; <?php echo $genre_data['m_genre']; ?>
  156. </label></a>
  157.  
  158. <?php } ?>
  159. </div>
  160.  
  161.  
  162.  
  163. <div class="col-xs-4">
  164. <h3>Country</h3>
  165. <?php
  166. $rs = $mysqli->query("select distinct(m_country)
  167. from movies where movie_status = '1'");
  168.  
  169. while($country_data = mysqli_fetch_assoc($rs)){
  170.  
  171. ?>
  172. <a href="javascript:void(0);" class="list-group-item">
  173. <input type="checkbox" class="item_filter country"
  174. value="<?php echo $country_data['m_country']; ?>" <?php
  175. if(in_array($country_data['m_country'],$country)){
  176. echo"checked"; } ?> >
  177. &nbsp;&nbsp; <?php echo $country_data['m_country'];
  178. ?> </a>
  179. <?php } ?>
  180. </div>
  181.  
  182. <div class="col-xs-4">
  183. <h3>Year</h3>
  184. <?php
  185. $rs = $mysqli->query( "select distinct(m_year)
  186. from movies where movie_status = '1'");
  187.  
  188. while($year_data = mysqli_fetch_assoc($rs)){
  189.  
  190. ?>
  191. <a href="javascript:void(0);" class="list-group-item">
  192. <input type="checkbox" class="item_filter year"
  193. value=" <?php echo $year_data['m_year']; ?>"
  194. <?php if(in_array($year_data['m_year'],$year))
  195. { echo"checked"; } ?> >
  196. &nbsp;&nbsp; <?php echo $year_data['m_year']; ?></a>
  197. <?php } ?>
  198. </div>
  199.  
  200. </div>
  201. </div>
  202. </div>
  203.  
  204.  
  205.  
  206. <div class="row">
  207. <div class="col-xs-12">
  208. <?php
  209.  
  210.  
  211. $query = "SELECT * FROM movies
  212. WHERE movie_status = '1' ";
  213. //filter query start
  214. if(!empty($genre)){
  215. $genredata =implode("','",$genre);
  216. $query .= " and m_genre in('$genredata')LIMIT
  217. {$startpoint} , {$per_page} ";
  218. }
  219.  
  220. if(!empty($country)){
  221. $countrydata =implode("','",$country);
  222. $query .= " and m_country
  223. in('$countrydata')LIMIT {$startpoint} , {$per_page} ";
  224. }
  225.  
  226. if(!empty($year)){
  227. $yeardata =implode("','",$year);
  228. $query .= " and m_year in('$yeardata')LIMIT
  229. {$startpoint} , {$per_page} ";
  230. }
  231. //filter query end
  232. $rs = mysqli_query($mysqli,$query) or die("Error :
  233. ".mysqli_error($mysqli));
  234. echo '<div class= "wrap">';
  235. // displaying paginaiton.
  236.  
  237. echo pagination($statement,$per_page,$page,$url='?');
  238.  
  239. echo "</div>";
Add Comment
Please, Sign In to add comment