Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]sronicowanie - paginacja
-stronnik-
post
Post #1





Goście







Witam
Jestem średni w php ale chciałbym napisać sobie paginacje i uzkysać taki efeket stronicowania:

[1][2][3]...[456] - początek
[1]...[14][15][16][17][18]...[456] - gdzieś w środku
[1]...[454][455][456] - koniec

Żeby nie było coś zrobiłem:

  1. <?php
  2.  
  3. //PAGINACJA START
  4. $results = 5; //Ilość na stronie
  5. $page_count = ceil($number_of_rows/$results); //Ilość stron w zaokrągleniu
  6. $page_ = isset($_GET['id2']) ? $_GET['id2'] : 1; //Na której stronie jestem
  7. $next = $page_ + 1; //Następna
  8. $back = $page_ - 1; //Poprzednia
  9. $start = $page_ * $results - $results; //Wyliczanka
  10. //PAGINACJA KONIEC
  11.  
  12. $stmt = $pdo -> prepare('SELECT * FROM `baza_email` LIMIT (IMG:style_emoticons/default/ohmy.gif) d, (IMG:style_emoticons/default/biggrin.gif) o');
  13. $stmt -> bindValue('(IMG:style_emoticons/default/ohmy.gif) d', $start, PDO::PARAM_INT);
  14. $stmt -> bindValue('(IMG:style_emoticons/default/biggrin.gif) o', 10, PDO::PARAM_INT);
  15. $stmt -> execute();
  16. $row_count = $stmt->rowCount();
  17. while($row_d = $stmt -> fetch()){
  18. $dane[] = $row_d;
  19. }
  20.  
  21.  
  22. if($page_ > 1) {
  23. echo '<a href="index-1.html"></a>
  24. <a href="index-' . $back. '.html"></a>';
  25. }
  26. $wstecz_jeden = $page_ - 1;
  27. $wstecz_dwa = $page_ - 2;
  28. if($wstecz_dwa > 0){
  29. echo '<a href="index-'.$wstecz_dwa.'.html">'.$wstecz_dwa.'</a>';
  30. }
  31. if($wstecz_jeden >= 1){
  32. echo '<a href="index-'.$wstecz_jeden.'.html">'.$wstecz_jeden.'</a>';
  33. }
  34. echo '<b><a>'.$page_.'</a></b>';
  35. if($next <= $page_count){
  36. echo '<a href="index-'.$next.'.html">'.$next.'</a>';
  37. }
  38. $page_count_1 = $page_count - 1;
  39. if($page_count == $page_ || $page_ == $page_count_1){ }else{
  40. echo '
  41. <a>...</a>
  42. <a href="index-' . $page_count. '.html">'.$page_count.'</a>
  43. <a href="index-' . $next. '.html"></a>
  44. <a href="index-' . $page_count. '.html"></a>';
  45. }
  46.  
  47.  
  48. ?>

Dziala ale zwraca:

18 1920 21 ... 13083


Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
abjk
post
Post #2





Grupa: Zarejestrowani
Postów: 29
Pomógł: 6
Dołączył: 5.04.2013
Skąd: W

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


Może być?

  1. <?php
  2. $number_of_rows = 1000;
  3.  
  4. //PAGINACJA START
  5. $results = 5; //Ilość na stronie
  6. $page_count = ceil($number_of_rows/$results); //Ilość stron w zaokrągleniu
  7. $page_ = isset($_GET['id2']) ? $_GET['id2'] : 1; //Na której stronie jestem
  8. $next = $page_ + 1; //Następna
  9. $back = $page_ - 1; //Poprzednia
  10. #$start = $page_ * $results - $results; //Wyliczanka
  11. //PAGINACJA KONIEC
  12.  
  13. if($page_ == 1) {
  14. echo '<b><a href="index-'.$page_.'.html">'.$page_.'</a></b>
  15. <a href="index-2.html">2</a>
  16. <a href="index-3.html">3</a>';
  17. }
  18.  
  19. if ($page_ > 1) {
  20. echo '<a href="index-1.html">1</a> ... ';
  21.  
  22. if(($back <= $page_count) && ($back > 1)){
  23. if ($page_ == $page_count) {
  24. echo '<a href="index-'.($back-1).'.html">'.($back-1).'</a> ';
  25. }
  26. echo '<a href="index-'.$back.'.html">'.$back.'</a>';
  27. }
  28.  
  29. echo ' <b><a>'.$page_.'</a></b> ';
  30.  
  31. if($next <= $page_count){
  32. echo '<a href="index-'.$next.'.html">'.$next.'</a>';
  33. if ($page_ == 2) {
  34. echo ' <a href="index-'.($next+1).'.html">'.($next+1).'</a>';
  35. }
  36. }
  37. }
  38.  
  39. if($page_ == $page_count || $page_ == $page_count-1) {} else {
  40. echo ' ... <a href="index-' . $page_count. '.html">'.$page_count.'</a>';
  41. }
  42. ?>
Go to the top of the page
+Quote Post

Posty w temacie
- stronnik   [PHP]sronicowanie - paginacja   14.02.2014, 11:21:57
- - abjk   Może być? [PHP] pobierz, plaintext <?php$numbe...   14.02.2014, 16:19:13
- - stronnikk   [PHP] pobierz, plaintext <?php$ile_z_lewej = 2;...   14.02.2014, 16:19:16


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: 14.10.2025 - 22:22