Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] pętla podstrony
krystian1991x
post
Post #1





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


Mam pytanie jak podzielić np wyświetlane newsy na strony czyli tak jak jest na tych większych portalach że np na strone pokazuje 10 newsów i potem trzeba przejść na następną i tak dalej i tak dalej a pod spodem są np numerki jako odnośniki do tych stron
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
krystian1991x
post
Post #2





Grupa: Zarejestrowani
Postów: 114
Pomógł: 0
Dołączył: 7.08.2010

Ostrzeżenie: (10%)
X----


heh mam aktualnie coś takiego
  1. <?php
  2.  
  3. $subpage = $_GET['page'];
  4. $perPage = 5;
  5.  
  6. if (!empty($_GET['subpage']) && (is_numeric($_GET['subpage'])))
  7. {
  8. $subpage = (int) $_GET['subpage'];
  9. }
  10.  
  11. if ($subpage < 1)
  12. {
  13. $subpage = 1;
  14. }
  15.  
  16. $start = ($subpage - 1) * $perPage;
  17.  
  18. $news_query = mysql_query('SELECT count(id)
  19. AS totality
  20. FROM news ');
  21.  
  22. $results_query= mysql_fetch_array( $news_query );
  23.  
  24. $news_results = $results_query['totality'];
  25.  
  26. $smarty->assign('news_totality',$news_results);
  27.  
  28. $result = mysql_query("SELECT id, title, author, text, img, date, commnets
  29. FROM news
  30. ORDER BY id DESC") or die("Niepoprawne zapytanie MySQL");
  31.  
  32.  
  33.  
  34. while ($news = mysql_fetch_array($result))
  35. {
  36.  
  37. $tablica[] = $news;
  38.  
  39. }
  40.  
  41. $smarty->assign('result',$tablica);
  42.  
  43. ?>

wszystkie przykłady odnoszą się do czystego php a jak ja mam wszystko to co tam jest zawrzeć w jednej tablicy i wyświetlić to w tpl ?! ;/

Aktualnie mam takie coś teraz nie wiem za bardzo jak to w smarty przedstawić ...

  1. <?php
  2.  
  3. $subpage = $_GET['page'];
  4. $perPage = 5;
  5.  
  6. if (!empty($_GET['subpage']) && (is_numeric($_GET['subpage'])))
  7. {
  8. $subpage = (int) $_GET['subpage'];
  9. }
  10.  
  11. if ($subpage < 1)
  12. {
  13. $subpage = 1;
  14. }
  15.  
  16. $start = ($subpage - 1) * $perPage;
  17.  
  18. $news_query = mysql_query('SELECT count(id)
  19. AS totality
  20. FROM news ');
  21.  
  22.  
  23. $result = mysql_query("SELECT id, title, author, text, img, date, commnets
  24. FROM news
  25. ORDER BY id DESC LIMIT $start, $perPage ") or die("Niepoprawne zapytanie MySQL");
  26.  
  27. if(mysql_real_escape_string((!isset($_GET['id'])) or empty($_GET['id'])))
  28. {
  29. while ($news = mysql_fetch_array($result))
  30. {
  31.  
  32. $tablica[] = $news;
  33.  
  34. }
  35. }
  36. $prev = $subpage - 1;
  37. $next = $subpage + 1;
  38. $prevLink = 'index.php?page='.$prev;
  39. $nextLink = 'index.php?page='.$next;
  40.  
  41. $ilosc_wierszy = mysql_num_rows($news_query);
  42.  
  43. if($subpage > 1)
  44. echo'<a style="text-decoration: none;" href="'.$prevLink.'">Poprzednia strona</a> ';
  45.  
  46. $stron=round($ilosc_wierszy/$perPage);
  47.  
  48. for($i=1; $i<=$stron; ++$i)
  49. {
  50. if($i==$subpage)
  51. echo $i;
  52. else
  53. echo '<a style="text-decoration: none;" href="index.php?page='.$i.'">'.$i.' </a>';
  54. }
  55. if($subpage < $stron)
  56. echo ' <a style="text-decoration: none;" href="'.$nextLink.'">Następna strona</a>';
  57.  
  58. $smarty->assign('result',$tablica);
  59.  
  60. ?>


Ten post edytował krystian1991x 19.10.2010, 21:34:35
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.10.2025 - 19:20