Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> stronicowanie na plikach txt
Apo
post 21.10.2005, 16:21:59
Post #1





Grupa: Zarejestrowani
Postów: 426
Pomógł: 1
Dołączył: 2.10.2005

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


Witam
Zrobiłem sobie księge gości w php i teraz chciałem zrobić stronicowanie np co 10 wpisów ale nie wiem jak sie za to zabrać. Czytałem klase nospor-a ale ona jest napisany na przykładzie mysql a mi chodzi o pliki tekstowe. Czy może ktoś dać przykład lub dokładnie opisać jak to sie robi :?
Z góry thx
Go to the top of the page
+Quote Post
bronx
post 21.10.2005, 16:40:52
Post #2





Grupa: Zarejestrowani
Postów: 333
Pomógł: 0
Dołączył: 4.03.2004

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


przykłąd (ja tak kiedyś miałem):

  1. <?php
  2. $base="ksiega/data.php"; 
  3. $table=array_reverse(file($base)); 
  4. $max=count($table); 
  5. $per_page = 10; 
  6. $first = $per_page * ($page - 1); 
  7. $last = $first + $per_page; 
  8.  
  9. for ($i=$first; $i<$last and $i<$max; $i++) { 
  10. $data = explode( "*|*", stripslashes( $table[$i] ) );
  11.  
  12. echo "wyglad ksiegi ze zmiennymi";
  13.  
  14. } 
  15.  
  16. for ($i = 1; $i <= $c; $i++){ 
  17. if($i != $_GET['page']){ 
  18. echo " <b><a href="$PHP_SELF?page=$i">" . $i . "</a> </b>"; 
  19. } 
  20. else { 
  21. echo "<font size=3 color=red><b>&nbsp" . $i . "&nbsp</b></font>"; 
  22. } 
  23. } 
  24. ?>


pozdrawiam
Go to the top of the page
+Quote Post
-Gość_Apo-
post 21.10.2005, 17:16:58
Post #3





Goście







A o co dokładniej w tym chodzi? :
  1. <?php
  2.  
  3. $first = $per_page * ($page - 1);
  4.  
  5. ?>
:?:
Go to the top of the page
+Quote Post
bronx
post 21.10.2005, 17:29:05
Post #4





Grupa: Zarejestrowani
Postów: 333
Pomógł: 0
Dołączył: 4.03.2004

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


Cytat(Gość_Apo @ 2005-10-21 18:16:58)
A o co dokładniej w tym chodzi? :
  1. <?php
  2.  
  3. $first = $per_page * ($page - 1);
  4.  
  5. ?>
:?:

od którego wpisu ma zacząć wyświetlać. Czyli np. w linku będzie page=3 czyli: 10 * (3-1) = 20 czyli na 3 stronie ma wyświetlic od 20 do 30 wpisu.

pozdrawiam
Go to the top of the page
+Quote Post
-Gość_Apo-
post 23.10.2005, 19:25:54
Post #5





Goście







hmmm mam jeszcze jeden problem. Wszystko jest ok gdyby nie to że wiświetla mi naprzemian wpisy jeden normalny news z pliku a drugi tak jak by była w pliku pista linia a tak nie jest sad.gif
Oto kod:

  1. <?php
  2.  
  3. if(file_exists($newsy_db)) {
  4.  
  5. $table = file($newsy_db);
  6. $max = count($table);
  7. $page = $_GET[page];
  8. $per_page = 10; 
  9. $first = $per_page * ($page - 1); 
  10. $last = $first + $per_page; 
  11. $ile = $max / $per_page;
  12.  
  13. for ($i = $first; $i < $last && $i< $max; $i++) {
  14. list($numer, $autor, $title, $licznik, $news, $newslong, $komentarze, $date) = explode('<>', $table[$i]);
  15.  
  16. if($use_emots_news == 'yes') {$news = str_replace($emotki, $emotki_nazwa, $news); }
  17. if($use_emots_title == 'yes') {$title = str_replace($emotki, $emotki_nazwa, $title);}
  18.  
  19. $title = stripslashes($title);
  20. $news = stripslashes($news);
  21. $autor = stripslashes($autor);
  22. echo '
  23. <div id="mainnews">
  24.  <div id="news"><b>'.$title.'</b> - '.$date.'</div>
  25.  <div id="widenews">'.$news.'</div>
  26.  <div id="news">dodał: '.$autor; 
  27. if($newslong !== '') { echo ' | czytań: '.$licznik.' - <a href="index.php?page='.$page.'&long='.$i.'" class="link">[Czytaj więcej...]</a>'; } 
  28.  </div>
  29. </div><p></p>';
  30. }
  31.  
  32. for ($i = 1; $i <= $ile; $i++){
  33.  if($i != $page){ 
  34.  echo '<b><a href="index.php?page='.$i.'">'.$i.'</a> </b>'; 
  35.  }
  36.  else { 
  37.  echo '<font size=3 color=red><b>'.$i.'</b></font>'; 
  38.  }
  39. }
  40. }
  41. else {
  42. echo 'Brak bazy newsów!';
  43. }
  44.  
  45. ?>
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 7.07.2025 - 00:03