Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php]problem ze stronnicowaniem
Forum PHP.pl > Forum > Przedszkole
droicyn
  1. <?php
  2.  
  3. // Dane z SQL'a do tablicy
  4. $count = 0;
  5. while($record_smiles = mysql_fetch_array($result_smiles))
  6. {
  7. $array_smiles[$count]['smile'] = $record_smiles['smile'];
  8. $array_smiles[$count]['file'] = $record_smiles['file'];
  9.  
  10. $count++;
  11. }
  12. if (isset($_GET['send']))
  13. {
  14. $int_poile = $_GET['submit_poile'];
  15. if(!isset($_GET['od']))
  16. {
  17. $int_od = 0;
  18.  
  19. }
  20. else
  21. {
  22. $int_od = $_GET['od'];
  23. }
  24. }
  25. else
  26. {
  27. $int_poile = 5;
  28. if(!isset($_GET['od']))
  29. {
  30. $int_od = 0;
  31.  
  32. }
  33. else
  34. {
  35. $int_od = $_GET['od'];
  36. }
  37. }
  38. $sql = "SELECT id, status, text_short, title, nick, image, link, date, mail FROM ne
    ws_news WHERE status='1' ORDER BY date DESC"
    ; 
  39. $result_num = mysql_query($sql);
  40. $newsy = 0;
  41. $newsy = mysql_num_rows($result_num);
  42.  
  43. $limit = ' LIMIT ' . $int_od . ', ' . $int_poile;
  44.  
  45. $sql = "SELECT id, status, text_short, title, nick, image, link, date, mail FROM ne
    ws_news WHERE status='1' ORDER BY date DESC $limit"
    ; 
  46. $result = mysql_query($sql);
  47.  
  48.  
  49. while($record = mysql_fetch_array($result))
  50. {
  51. if ($record['status'] == 1)
  52. {
  53. $id_news = $record['id'];
  54. $num_comments = 0;
  55.  
  56. $sql = "SELECT id, id_news FROM news_comments WHERE id_news='$id_news'";
  57. $result_comments = mysql_query($sql);
  58. $num_comments = mysql_num_rows($result_comments);
  59.  
  60. for ($i = 0; $i < count($array_smiles); $i++)
  61. {
  62. $record['text_short'] = str_replace($array_smiles[$i]['smile'], '<img src="images/smiles/icon_' . $array_smiles[$i]['file'] . '.gif" />', $record['text_short']);
  63. }
  64.  
  65. if(!empty($record['image']))
  66. {
  67. $image = '<img src="images/avatars/' . $record['image'] . '">';
  68. }
  69. else
  70. {
  71. $image = '';
  72. }
  73.  
  74. $link_short = $record['link'];
  75.  
  76. if(strlen($link_short) > 20)
  77. {
  78. $link_short = substr($link_short, 0,20);
  79. $link_short .= '...';
  80. }
  81.  
  82. if (!empty($record['link']))
  83. {
  84. $link = '<br /><br /><b>Link:</b> <a href="' . $record['link'] . '" target="_blank">' . $link_short . '</a>';
  85. }
  86. else
  87. {
  88. $link = '';
  89. }
  90.  
  91. //wyswietlam tutaj nick itp itd
  92.  
  93.  
  94. }
  95.  
  96. }
  97.  
  98. <table class="news_short" cellpadding="0" cellspacing="0" width="300">
  99. <form action="index.php" method="get">
  100. <tr>
  101. <td class="nick" width="70" align="center">Pokaż po</td>
  102. <td class="nick" width="60" align="center"><select name="submit_poile"><option>1<option selected>5<option>10<option>25</td>
  103. <td class="nick" width="110" align="center"> newsów na stronie</td>
  104. <td class="nick" width="60" align="center"><input type="submit" name="send" value="Pokaż" /></td>
  105. </tr>
  106. </form>
  107. </table>
  108. <br /><br />';
  109. $prev = $int_od - $int_poile;
  110. if($prev >=0)
  111. {
  112. echo '<a href="index.php?od=' . $prev . '"><span class="arrows">&laquo; Poprzednia&nbsp;&nbsp;</span></a>';
  113.  
  114. }
  115. else
  116. {
  117. echo '<span class="arrows2">&laquo; Poprzednia&nbsp;&nbsp;</span>';
  118.  
  119. }
  120. $_GET['x'] = 0;
  121. for($j = 0; $j<$newsy; $j+=$int_poile)
  122. {
  123. if ($j != 0)
  124. {
  125. echo '<span class="arrows">&nbsp;|&nbsp;</span>';
  126. }
  127. if($j == $_GET['od'])
  128. {
  129. echo '<b>'.($x + 1).'</b>';
  130. }
  131. else
  132. {
  133. echo '<a href="index.php?od=' . $j . '">' .($x + 1). '</a>';
  134. }
  135. $x++;
  136. }
  137. $next = $int_od + $int_poile;
  138. if($next<floor($newsy))
  139. {
  140. echo '<a href="index.php?od=' .$next . '"><span class="arrows">&nbsp;&nbsp;Następna&nbsp;&raquo;</span></a>';
  141.  
  142. }
  143. else
  144. {
  145. echo '<span class="arrows2">&nbsp;&nbsp;Następna&nbsp;&raquo;</span>';
  146.  
  147. }
  148.  
  149.  
  150. ?>
  151. i chodzi o to ze gdy wybiore zeby sortowal pojedynczo tzn zeby na kazdej stronie
     byl jeden news to podzieli dobrze ale gdy przejde na kolejna stronke to on zapomina o tym ze ma dzielic pojedynczo i d
    zieli ze jest ich po 5! 5 to jest domyslne jak to poprawic? 


---dodane---
I mam problem taki, że gdy wybiorę sortowanie po 1 newsie na stronie to gdy przejde np do 3 znow wyswietla mi po 5( bo tak jest ustawione domyslnie) jak mam zrobic zeby pamietal mi ze ma sortowac po 1 newsie albo gdyby tych newsow bylo 50 zeby to dzialalo przy sortowaniu po 10 na stronie(bo mam opcje ze sortuje 1 5 10 i 25)mam nadzieje ze teraz jest wszystko wporzadku i moj temat nie zostanie zablokowany
mike
Zamykam

Co to ma być?
Myślisz że jak walniesz w temacie problem ze stronicowaniem to już? Każdy się rzuci na kod i będzie go testował i sprawdzał jak Tobie nawet się słowa tekstu napisać nie chciało?

Poproszę na PW uzupełnioną treść wątku, to otworzę.

P.S.
Jak ja nie lubię takich ignorantów ...


---
Po uzupełnieniu wątku, otwieram.
droicyn
Teraz mam nowy problem. Dowiedziałem się że trzeba to zrobic stosując zmienne get, że do linku trzeba dodac zmienna get.Tzn ja tak to zrozumialem i moj skrypt wyglada teraz tak:
  1. <?php
  2.  
  3.  
  4.  
  5. // Dane z SQL'a do tablicy
  6. $count = 0;
  7. while($record_smiles = mysql_fetch_array($result_smiles))
  8. {
  9. $array_smiles[$count]['smile'] = $record_smiles['smile'];
  10. $array_smiles[$count]['file'] = $record_smiles['file'];
  11.  
  12. $count++;
  13. }
  14. if (isset($_POST['send']))
  15. {
  16. $int_poile = $_POST['submit_poile'];
  17. if(!isset($_GET['od']))
  18. {
  19. $int_od = 0;
  20.  
  21. }
  22. else
  23. {
  24. $int_od = $_GET['od'];
  25. }
  26. }
  27. else
  28. {
  29. $int_poile = 5;
  30. if(!isset($_GET['od']))
  31. {
  32. $int_od = 0;
  33.  
  34. }
  35. else
  36. {
  37. $int_od = $_GET['od'];
  38. }
  39. }
  40. $sql = "SELECT id, status, text_short, title, nick, image, link, date, mail FROM ne
    ws_news WHERE status='1' ORDER BY date DESC"
    ; 
  41. $result_num = mysql_query($sql);
  42. $newsy = 0;
  43. $newsy = mysql_num_rows($result_num);
  44.  
  45. $limit = ' LIMIT ' . $int_od . ', ' . $int_poile;
  46.  
  47. $sql = "SELECT id, status, text_short, title, nick, image, link, date, mail FROM ne
    ws_news WHERE status='1' ORDER BY date DESC $limit"
    ; 
  48. $result = mysql_query($sql);
  49.  
  50.  
  51. while($record = mysql_fetch_array($result))
  52. {
  53. if ($record['status'] == 1)
  54. {
  55. $id_news = $record['id'];
  56. $num_comments = 0;
  57.  
  58. $sql = "SELECT id, id_news FROM news_comments WHERE id_news='$id_news'";
  59. $result_comments = mysql_query($sql);
  60. $num_comments = mysql_num_rows($result_comments);
  61.  
  62. for ($i = 0; $i < count($array_smiles); $i++)
  63. {
  64. $record['text_short'] = str_replace($array_smiles[$i]['smile'], '<img src="images/smiles/icon_' . $array_smiles[$i]['file'] . '.gif" />', $record['text_short']);
  65. }
  66.  
  67. if(!empty($record['image']))
  68. {
  69. $image = '<img src="images/avatars/' . $record['image'] . '">';
  70. }
  71. else
  72. {
  73. $image = '';
  74. }
  75.  
  76. $link_short = $record['link'];
  77.  
  78. if(strlen($link_short) > 20)
  79. {
  80. $link_short = substr($link_short, 0,20);
  81. $link_short .= '...';
  82. }
  83.  
  84. if (!empty($record['link']))
  85. {
  86. $link = '<br /><br /><b>Link:</b> <a href="' . $record['link'] . '" target="_blank">' . $link_short . '</a>';
  87. }
  88. else
  89. {
  90. $link = '';
  91. }
  92.  
  93. // tu wyswietlam z bazy danych nick tytul mail avatar i tresc newsa
  94.  
  95. }
  96.  
  97. }
  98.  
  99. <table class="news_short" cellpadding="0" cellspacing="0" width="300">
  100. <form action="index.php" method="post">
  101. <tr>
  102. <td class="nick" width="70" align="center">Pokaż po</td>
  103. <td class="nick" width="60" align="center"><select name="submit_poile"><option>1<option selected>5<option>10<option>25</td>
  104. <td class="nick" width="110" align="center"> newsów na stronie</td>
  105. <td class="nick" width="60" align="center"><input type="submit" name="send" value="Pokaż" /></td>
  106. </tr>
  107. </form>
  108. </table>
  109. <br /><br />';
  110. $submit_poile = $_GET['submit_ile'];
  111. $prev = $int_od - $int_poile;
  112. if($prev >=0)
  113. {
  114. if(isset($_GET['submit_ile']))
  115. {
  116. echo '<a href="index.php?od=' . $prev .'&po=' . $submit_ile . '"><span class="arrows">&laquo; Poprzednia&nbsp;&nbsp;</span></a>';
  117. }
  118. else
  119. {
  120. echo '<a href="index.php?od=' . $prev . '"><span class="arrows">&laquo; Poprzednia&nbsp;&nbsp;</span></a>';
  121. }
  122. }
  123. else
  124. {
  125. echo '<span class="arrows2">&laquo; Poprzednia&nbsp;&nbsp;</span>';
  126.  
  127. }
  128. $x = 0;
  129. for($j = 0; $j<$newsy; $j+=$int_poile)
  130. {
  131. if ($j != 0)
  132. {
  133. echo '<span class="arrows">&nbsp;|&nbsp;</span>';
  134. }
  135. if($j == $_GET['od'])
  136. {
  137. echo '<b>'.($x + 1).'</b>';
  138. }
  139. else
  140. {
  141. if(isset($_GET['submit_ile'])
  142. {
  143. echo '<a href="index.php?od=' . $j . '&po'. $submit_ile .'">' .($x + 1). '</a>';
  144. }
  145. else
  146. {
  147. echo '<a href="index.php?od=' . $j . '">' .($x + 1). '</a>';
  148. }
  149. }
  150. $x++;
  151. }
  152. $next = $int_od + $int_poile;
  153. if($next<floor($newsy))
  154. {
  155. if(isset($_GET['submit_ile']))
  156. {
  157. echo '<a href="index.php?od=' . $next .'&po='. $submit_ile . '"><span class="arrows">&laquo; Poprzednia&nbsp;&nbsp;</span></a>';
  158. }
  159. else
  160. {
  161. echo '<a href="index.php?od=' .$next . '"><span class="arrows">&nbsp;&nbsp;Następna&nbsp;&raquo;</span></a>';
  162. }
  163. }
  164. else
  165. {
  166. echo '<span class="arrows2">&nbsp;&nbsp;Następna&nbsp;&raquo;</span>';
  167.  
  168. }
  169.  
  170.  
  171. ?>


I chodzi o to ze to i tak nie dziala prosilbym o pomoc. bo nadal zapomina mi o tym w jaki sposob ma wyswietlac newsy czy po 1 na stronce caly czas czy w inny sposob.Podzieli dobrze a gdy zrobie przejscie wraca do domyslnych czyli do tego ze sortuje po 5.Pozdrawiam.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.