Advertisement
elektrogil

pagination1

Apr 27th, 2014
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.69 KB | None | 0 0
  1. include 'includes/connection.php';
  2.  
  3. $sql = mysqli_query($conn,"SELECT id, cve_prod, desc_prod FROM abb ORDER BY id ASC");
  4.  
  5. $nr = mysqli_num_rows($sql);
  6. if (isset($_GET['pn'])) {
  7.     $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']);
  8.    
  9. } else {
  10.     $pn = 1;
  11. }
  12.  
  13. $itemsPerPage = 10;
  14. $lastPage = ceil($nr / $itemsPerPage);
  15. if ($pn < 1) {
  16.     $pn = 1;
  17. } else if ($pn > $lastPage) {
  18.     $pn = $lastPage;
  19. }
  20.  
  21. $centerPages = "";
  22. $sub1 = $pn - 1;
  23. $sub2 = $pn - 2;
  24. $add1 = $pn + 1;
  25. $add2 = $pn + 2;
  26. $display = 'productos.html';
  27. if ($pn == 1) {
  28.     $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  29.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  30. } else if ($pn == $lastPage) {
  31.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  32.     $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  33. } else if ($pn > 2 && $pn < ($lastPage - 1)) {
  34.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
  35.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  36.     $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  37.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  38.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
  39. } else if ($pn > 1 && $pn < $lastPage) {
  40.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  41.     $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  42.     $centerPages .= '&nbsp; <a href="' . $display . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  43. }
  44. $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
  45. $sql2 = mysqli_query($conn,"SELECT id, cve_prod, desc_prod FROM abb ORDER BY id ASC $limit");
  46.  
  47. $paginationDisplay = "";
  48. if ($lastPage != "1"){
  49.     $paginationDisplay .= 'Página <strong>' . $pn . '</strong> de ' . $lastPage. '&nbsp;  &nbsp;  &nbsp; ';
  50.     if ($pn != 1) {
  51.         $previous = $pn - 1;
  52.         $paginationDisplay .=  '&nbsp; <script>$("#home").show();$("#framecontent2").show();$("#framecontent3").show();</script>  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '"> Atras</a> ';
  53.     }
  54.     $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
  55.     if ($pn != $lastPage) {
  56.         $nextPage = $pn + 1;
  57.         $paginationDisplay .=  '&nbsp;  <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $nextPage . '"> Siguiente</a> ';
  58.     }
  59. }
  60. $outputList = '';
  61.  
  62. while($row = mysqli_fetch_array($sql2)){
  63.  
  64.     $id = $row["id"];
  65.     $cve_prod = $row["cve_prod"];
  66.     $desc_prod = $row["desc_prod"];
  67.  
  68.     $outputList .= "<br/><div style='display:inline-block; width:150px; margin-left:5px;'>" . $cve_prod ."</div>" . "&nbsp;&nbsp;&nbsp;&nbsp;" . "<div style='display:inline-block;margin-left:92px; margin-right:64px;'>" . $desc_prod ."</div><br/>" ;
  69.    
  70. }
  71.  
  72. ?>
  73. <html>
  74. <head>
  75. <meta charset="utf-8">    
  76. <title>JR COMMICH</title>
  77. <link rel="stylesheet" href="css/style.css">
  78.   <link rel="stylesheet" href="css/bootstrap.css">
  79.   <link rel="stylesheet" href="css/jquery-ui-1.9.2.custom.css">
  80.  
  81. <script type="text/javascript">
  82.     $("#home").hide();
  83.     $("#framecontent2").hide();
  84.     $("#framecontent3").hide();
  85. </script>
  86. </head>
  87. <body style="background:#eee url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAMAAAC6sdbXAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF3d3d////riJKgAAAAAJ0Uk5T/wDltzBKAAAAFUlEQVR42mJgBAEGGMmAxAYCgAADAAGGABmnk/7aAAAAAElFTkSuQmCC);">
  88.    
  89.     <!-- <div id="framecontent2">
  90.   <div class="innertube"></div>
  91.   </div>
  92.  
  93.   <div id="framecontent3">
  94.   <div class="innertube"></div>
  95.   </div>
  96.   <!-- INICIO DEL MENU -->
  97.   <!--FIN DEL MENU -->
  98.    
  99.    <div style="margin-left:64px; margin-right:64px;">
  100.      <h2 style="font-size:26px;color:#b3292e;">ABB <p style=" display:inline-block;color:black;"> - Artículos:<?php echo $nr; ?> - </p> JR Una Nube de Soluciones para el Integrador</h2>
  101.    </div>
  102.    <div id="maincontent3" style="background-image:url('logo_nube2.png'); background-position:center; background-size:516px 395px; background-repeat:no-repeat;">
  103.            
  104.       <div style="margin-left:220px; margin-right:220px; padding:6px;  border:#b3292e 2px solid; border-radius:10px; font-weight:bold;"><?php echo "" . $paginationDisplay; ?></div><br>
  105.       <div style="margin-left:226px; margin-right:226px;"><div style="color:#b3292e; display:inline-block; width:200px; font-size:30px;">Clave</div><div style=" color:#b3292e;margin-left:65px; display:inline-block; width:250px; font-size:30px;">Descripcion</div></div>
  106.       <div style="margin-left:226px; margin-right:100px; margin-bottom:40px; font-weight:bold;"><?php print "$outputList"; ?></div> <br>
  107.       <div style="margin-left:220px; margin-right:220px; padding:6px; font-weight:bold; border:#b3292e 2px solid; border-radius:10px; "><?php echo $paginationDisplay; ?></div>
  108.       </div>
  109.      
  110.       <div id="home" style="margin-left:220px; margin-right:220px; padding:6px; font-weight:bold;"><a href="productos.html">Regresar al catálogo</a></div>
  111.      
  112.      
  113.       <!-- FOOTER -->
  114.   <!-- <div class="navbar navbar-inverse navbar-fixed-bottom">
  115.     <div class="container">
  116.       <p class="navbar-text pull-left italic">ventas@ &nbsp;&nbsp; | &nbsp;&nbsp; (55)  &nbsp;&nbsp; | &nbsp;&nbsp; <a href="aviso_privacidad.html">Aviso de Privacidad</a> </p>
  117.       <p class="navbar-text pull-right">&#169;&nbsp;Copyright 2013 DERECHOS RESERVADOS </p>
  118.     </div>
  119.   </div>
  120. <!-- FOOTER ENDS -->
  121.  
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement