Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Stronicowanie
Forum PHP.pl > Forum > PHP
djgarsi
Witam. Ze skryptem stronicowania "użeram się" już długo. Próbowałem w js - nie wyszło, w ajax'ie - to samo.
Moja wiedza na temat php dopiero raczkuje.sad.gif Dlatego chciałbym, aby ktoś pomógł mi przerobić skrypt download'u, aby co określoną liczbę plików rozpoczynała się nowa strona.

Oto mój plik download.php
  1. $download_start = get_template('download_start.tpl');
  2. echo $download_start;
  3.  
  4. if($_GET['cat'] >= 1)
  5. {
  6.  
  7. //---
  8.  
  9. $Query_cat="SELECT * FROM kategorie WHERE id='".mysql_real_escape_string($_GET['cat'])."' ORDER BY name ASC";
  10. $result_cat = mysql_query($Query_cat) or die (mysql_error());
  11. while ( $row_cat = mysql_fetch_array($result_cat))
  12. {
  13.  
  14. $download_info_cat = get_template('download_info_cat.tpl');
  15. $download_info_cat = str_replace("{cat}", $row_cat['name'], $download_info_cat);
  16. $download_info_cat = str_replace("{l_cat}", $lang['cat'], $download_info_cat);
  17. echo $download_info_cat;
  18.  
  19. $Query_pcat="SELECT * FROM kategorie WHERE pod='".$row_cat['id']."' ORDER BY name ASC";
  20. $result_pcat = mysql_query($Query_pcat) or die (mysql_error());
  21. while ( $row_pcat = mysql_fetch_array($result_pcat))
  22. {
  23.  
  24. $res = mysql_query("SELECT * FROM file WHERE cat='".$row_pcat["id"]."' and active='1'");
  25. $ile2 = mysql_num_rows($res);
  26.  
  27. echo'&nbsp;&nbsp;<a href="podkategoria,'.$row_pcat['id'].','.namen($row_pcat['name']).'.html"></a>';
  28.  
  29. }
  30.  
  31. $res = mysql_query("SELECT * FROM file WHERE cat='".mysql_real_escape_string($_GET['cat'])."' and active='1'");
  32. $ile2 = mysql_num_rows($res);
  33.  
  34. if($ile2 >= 1)
  35. {
  36. echo'';
  37. }
  38.  
  39. $Query_file="SELECT * FROM file WHERE cat='".mysql_real_escape_string($_GET['cat'])."' ORDER BY id DESC";
  40. $result_file = mysql_query($Query_file) or die (mysql_error());
  41. while ( $row_file = mysql_fetch_array($result_file))
  42. {
  43.  
  44. $download_info_file = get_template('download_info_file.tpl');
  45.  
  46. $download_info_file = str_replace("{id}", $row_file['id'], $download_info_file);
  47. $download_info_file = str_replace("{name}", $row_file['name'], $download_info_file);
  48. $download_info_file = str_replace("{name_n}", namen($row_file['name']), $download_info_file);
  49. $download_info_file = str_replace("{data}", $row_file['data'], $download_info_file);
  50. $download_info_file = str_replace("{pobran}", $row_file['pobran'], $download_info_file);
  51. $download_info_file = str_replace("{licencja}", $row_file['licencja'], $download_info_file);
  52. $download_info_file = str_replace("{opis}", $row_file['opis'], $download_info_file);
  53. $download_info_file = str_replace("{l_data}", $lang['dodano'], $download_info_file);
  54. $download_info_file = str_replace("{l_pobran}", $lang['pobran'], $download_info_file);
  55. $download_info_file = str_replace("{l_licencja}", $lang['licencja'], $download_info_file);
  56.  
  57. if($row_file["img"] == "")
  58. {
  59. $download_info_file = str_replace("{img}", "", $download_info_file);
  60. }
  61. else
  62. {
  63. $download_info_file = str_replace("{img}", $row_file['img'], $download_info_file);
  64. }
  65.  
  66. echo $download_info_file;
  67.  
  68. }
  69.  
  70. }
  71.  
  72. //---
  73.  
  74. }
  75. else if($_GET['pcat'] >= 1)
  76. {
  77.  
  78. //---
  79.  
  80. $Query_catt="SELECT * FROM kategorie WHERE id='".mysql_real_escape_string($_GET['pcat'])."'";
  81. $result_catt = mysql_query($Query_catt) or die (mysql_error());
  82. while ( $row_catt = mysql_fetch_array($result_catt))
  83. {
  84.  
  85. $download_info_cat = get_template('download_info_cat.tpl');
  86. $download_info_cat = str_replace("{cat}", $row_catt['name'], $download_info_cat);
  87. $download_info_cat = str_replace("{l_cat}", $lang['cat'], $download_info_cat);
  88. echo $download_info_cat;
  89.  
  90. }
  91.  
  92. $Query_file="SELECT * FROM file WHERE cat='".mysql_real_escape_string($_GET['pcat'])."' ORDER BY id DESC";
  93. $result_file = mysql_query($Query_file) or die (mysql_error());
  94. while ( $row_file = mysql_fetch_array($result_file))
  95. {
  96.  
  97. $download_info_file = get_template('download_info_file.tpl');
  98.  
  99. $download_info_file = str_replace("{id}", $row_file['id'], $download_info_file);
  100. $download_info_file = str_replace("{name}", $row_file['name'], $download_info_file);
  101. $download_info_file = str_replace("{name_n}", namen($row_file['name']), $download_info_file);
  102. $download_info_file = str_replace("{data}", $row_file['data'], $download_info_file);
  103. $download_info_file = str_replace("{pobran}", $row_file['pobran'], $download_info_file);
  104. $download_info_file = str_replace("{licencja}", $row_file['licencja'], $download_info_file);
  105. $download_info_file = str_replace("{opis}", substr($row_file['opis'], 0, 200), $download_info_file);
  106. $download_info_file = str_replace("{l_data}", $lang['dodano'], $download_info_file);
  107. $download_info_file = str_replace("{l_pobran}", $lang['pobran'], $download_info_file);
  108. $download_info_file = str_replace("{l_licencja}", $lang['licencja'], $download_info_file);
  109.  
  110. if($row_file["img"] == "")
  111. {
  112. $download_info_file = str_replace("{img}", "", $download_info_file);
  113. }
  114. else
  115. {
  116. $download_info_file = str_replace("{img}", $row_file['img'], $download_info_file);
  117. }
  118.  
  119. echo $download_info_file;
  120.  
  121. }
  122.  
  123. //---
  124.  
  125. }
  126. else
  127. {
  128.  
  129. //---
  130.  
  131. $Query_cat="SELECT * FROM kategorie WHERE pod='0' ORDER BY name ASC";
  132. $result_cat = mysql_query($Query_cat) or die (mysql_error());
  133. while ( $row_cat = mysql_fetch_array($result_cat))
  134. {
  135. echo'<b><a href="kategoria,'.$row_cat['id'].','.namen($row_cat['name']).'">'.$row_cat['name'].'</a></b><br>';
  136.  
  137. $Query_pcat="SELECT * FROM kategorie WHERE pod='".$row_cat['id']."' ORDER BY name ASC";
  138. $result_pcat = mysql_query($Query_pcat) or die (mysql_error());
  139. while ( $row_pcat = mysql_fetch_array($result_pcat))
  140. {
  141.  
  142. $res = mysql_query("SELECT * FROM file WHERE cat='".$row_pcat["id"]."' and active='1'");
  143. $ile2 = mysql_num_rows($res);
  144.  
  145. echo'&nbsp;&nbsp;<a href="podkategoria,'.$row_pcat['id'].','.namen($row_pcat['name']).'.html">'.$row_pcat['name'].' ['.$ile2.']</a><br>';
  146.  
  147. }
  148.  
  149. }
  150.  
  151. //---
  152. }
  153.  
  154. $download_end = get_template('download_end.tpl');
  155. echo $download_end;


Proszę o pomoc.sad.gif
R4D3K
Witam, rozumiem, że chcesz paginację linków do pobrania questionmark.gif Jeśli tak to musisz użyć słowa kluczowego LIMIT w zapytaniu MySQL. LIMIT pobiera 2 parametry rekord od którego czytać oraz ile rekordów czytać np. LIMIT 0,5 pobierze 5 pierwszych rekordów, LIMIT 10,5 pobierze 5 rekordów od 10 licząc itp. Czyli potrzebujesz jeszcze parametru page w skrypcie, który Ci powie na której podstronie się znajduje user. np.
  1. If (isset($_GET['page'] {
  2. if (!is_int($_GET['page']) { $page=1; }
  3. else { $page=$_GET['page']; }
  4. $ile_na_stronie=5;
  5. $offset=$page*$ile_na_stronie;
  6. $sql='SELECT ........ WHERE LIMIT '.$offset.', '.$ile_na_stronie;
  7. // dalsza cześć aplikacji
  8. }

W ten sposób sobie zorganizujesz wyświetlanie wyników dalej musisz zrobić linki do następnych podstron:
  1. If ($page>1) { echo '<a href="skrypt.php?page='.($page+1).'DALEJ</a>';
  2. If ($page<$max) { echo '<a href="skrypt.php?page='.($page-1).'POPRZEDNIA</a>';

Czy to w taki lub inny sposób, zmienna $max=$ilosc_rekordow_w_tabeli*$ile_na_stronie; to ilość rekordów w tabeli, które możesz policzyć COUNTem
Mam nadzieje, że pomogłem.. Kod pisany jest z głowy, także może coś nie działać.
djgarsi
Niestety jest błąd.sad.gif
Parse error: syntax error, unexpected T_IF in /home/djgarsi/domains/djgarsi.pl/public_html/stronicowanie.php on line 4
Blame
  1. If ($page>1) { echo '<a href="skrypt.php?page='.($page+1).'DALEJ</a>';
  2. If ($page<$max) { echo '<a href="skrypt.php?page='.($page-1).'POPRZEDNIA</a>';

Usuń stąd te dwie klamry otwierające.
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.