Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Ustawienie htaccess do paginacji
Dissio
post
Post #1





Grupa: Zarejestrowani
Postów: 33
Pomógł: 0
Dołączył: 25.11.2014

Ostrzeżenie: (0%)
-----


Witajcie, ucze sie php i potrzebuje do tego paginacji, uzywam tego skryptu:

  1.  
  2. // zainkludowanie database
  3. include_once('db_connection.php');
  4. if($mysqli->connect_errno) die("Connect failed: %s\n". $mysqli->connect_error);
  5. // PAGINACJA SEKCJA
  6. //-------------------------------------------------------------------------------------------
  7. ////////////// Zapytanie query:
  8. $query = $mysqli -> query ("SELECT * FROM definicje");
  9. // ZAPYTANIEEE
  10. $number_of_pages = $query -> num_rows; // Ile jest wszystkich rekordów
  11.  
  12. if (isset($_GET['pn']))
  13. { // Get pn from URL vars if it is present
  14. $pn = preg_replace('#[^0-9]#i', '', $_GET['pn']); // filtr
  15. //$pn = ereg_replace("[^0-9]", "", $_GET['pn']); // zabezpieczenie
  16. }
  17. else
  18. {
  19. $pn = 1;
  20. }
  21. //Ile na stronie:
  22. $itemsPerPage = 4;
  23. // Zaokrlaglenie strony:
  24. $lastPage = ceil($number_of_pages / $itemsPerPage);
  25.  
  26. if ($pn < 1) {
  27. $pn = 1;
  28. } else if ($pn > $lastPage) {
  29. $pn = $lastPage;
  30. }
  31.  
  32. $centerPages = "";
  33. $sub1 = $pn - 1;
  34. $sub2 = $pn - 2;
  35. $add1 = $pn + 1;
  36. $add2 = $pn + 2;
  37. if ($pn == 1) {
  38. $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  39. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  40. } else if ($pn == $lastPage) {
  41. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  42. $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  43. } else if ($pn > 2 && $pn < ($lastPage - 1)) {
  44. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub2 . '">' . $sub2 . '</a> &nbsp;';
  45. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  46. $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  47. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  48. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add2 . '">' . $add2 . '</a> &nbsp;';
  49. } else if ($pn > 1 && $pn < $lastPage) {
  50. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $sub1 . '">' . $sub1 . '</a> &nbsp;';
  51. $centerPages .= '&nbsp; <span class="pagNumActive">' . $pn . '</span> &nbsp;';
  52. $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $add1 . '">' . $add1 . '</a> &nbsp;';
  53. }
  54.  
  55. $limit = 'LIMIT ' .($pn - 1) * $itemsPerPage .',' .$itemsPerPage;
  56.  
  57.  
  58. $sql2 = $mysqli -> query("SELECT * FROM definicje ORDER BY id DESC $limit ");
  59.  
  60. $paginationDisplay = "";
  61. if ($lastPage != "1"){
  62. $paginationDisplay .= '<strong>Strona </strong>' . $pn . '</strong> z ' . $lastPage. '&nbsp; &nbsp; &nbsp; ';
  63.  
  64. if ($pn != 1) {
  65. $previous = $pn - 1;
  66. $paginationDisplay .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $previous . '" style= "text-decoration:none; color:red;"><strong> Poprzednia </strong></a> ';
  67. }
  68.  
  69. $paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
  70.  
  71. if ($pn != $lastPage) {
  72. $Page = $pn + 1;
  73. $paginationDisplay .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?pn=' . $Page . ' " style= "text-decoration:none"; "><strong ><span style="color:red;">Następna <span></strong> </a> ';
  74. }
  75. }
  76.  



jak wyglada link kiedy przejde np do strony 2

  1. index.php?pn=2


czy ktos moglby mnie pokierowac, ewent. napisac z komentarzem htacces ze np przechodze do strony 2 to mam index.php/strona_2

Z gory bardzo dziekuje Pozdrawiam
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.08.2025 - 18:28