Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Ograniczenie wyników wyświetlanych na stronie
Bitkosa
post
Post #1





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 21.10.2009

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


Mam pytanie jak ograniczyć liczbę wyników wyświetlanych na stronie i jak zrobić strony poprzednią i następną(IMG:style_emoticons/default/questionmark.gif) Proszę o pomoc

Oto kod

  1. <?
  2.  
  3. $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM movies WHERE dodajacy_id='".$id."'"),0);
  4. if ($total_results <= 0)
  5. {
  6. echo '<br />Użytkownik nie dodał jeszcze żadnego filmu.<br />';
  7. }
  8.  
  9. else
  10. {
  11.  
  12. $sql = mysql_query("SELECT * FROM movies WHERE dodajacy_id='".$id."' ORDER BY id DESC");
  13. while($row = mysql_fetch_array($sql)) {
  14. $content = strip_tags($row['description']);
  15. if (strlen($content) > 65)
  16. {
  17. $content = substr($content, 0, 65)."...";
  18. }
  19. if ($row['import'] == 1) {
  20. $image = '<img align="absmiddle" src="'.$site_url.'/games/images/'.$row['url'].'.png" width="60" height="60" />';}
  21. else if ($row['import'] == 3) {
  22. $image = '<img align="top" src="'.$site_url.'/games/images/'.$row['image'].'" width="60" height="60" />';}
  23. else {
  24. $image = '<img align="absmiddle" src="'.$row['image'].'" width="60" height=60" />';}
  25.  
  26. if ($seo_on == 0) {
  27. $game_url = 'index.php?task=view&id='.$row['id'].'';}
  28. else {
  29. $abcd= $row['name'];
  30. $abcd = str_replace (" ", "-", $abcd);
  31. $abcd = preg_replace ( "/[\.,\";'\:]/", "", $abcd );
  32. $movie_url = 'view/'.$row['id'].'/'.$abcd.'.html';
  33. }
  34. echo '<div style="height:62px; color:#000000; background:#ffffff; margin-left:0px; margin-right:0px; border:0px solid #000000; " align="left"><strong><a href="'.$site_url.'/'.$game_url.'">&nbsp;'.$image.'&nbsp;&nbsp;</a><a href="'.$site_url.'/'.$movie_url.'">'.$row['name'].'</strong></a></div>';}
  35. }
  36.  
  37.  
  38. ?>
Go to the top of the page
+Quote Post
-lukasamd-
post
Post #2





Goście







Poczytaj o LIMIT w SQL oraz paginacji w PHP.
Łącząc obie te sprawy, możesz sobie zrobić niemal dowolny podział na strony.
Go to the top of the page
+Quote Post
altruista2
post
Post #3





Grupa: Zarejestrowani
Postów: 127
Pomógł: 32
Dołączył: 8.02.2010

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


Już pomagałem w podobnym temacie:
Temat: Stronnicowanie mysql bd

  1. <?
  2.  
  3. $ile_newsow_na_stronie = 3;
  4.  
  5. $s = intval($_GET['s']) - 1;
  6. list($ilosc) = @mysql_fetch_row(mysql_query("select count(*) from wpisy WHERE 1"));
  7.  
  8. if(($s < 0) || (($s * $ile_newsow_na_stronie) > $ilosc)) $s = 0;
  9.  
  10. $q = mysql_query("select id, tytul, tresc, adres from wpisy WHERE 1 order by id desc limit ".($s * $ile_newsow_na_stronie).", $ile_newsow_na_stronie");
  11. while(list($id, $tytul, $tresc, $adres) = @mysql_fetch_row($q)) {
  12. echo '<h2><b><a href=http://'.$adres.' >'.$tytul.'</b></h2></a><br><div class="story"> '.$tresc.'<br /><br></div>';
  13. }
  14.  
  15. $max = intval($ilosc / $ile_newsow_na_stronie);
  16. for($i=0;$i<$max;$i++) {
  17. if($s == $i) {
  18. echo ($i + 1).' ';
  19. }else{
  20. echo '<a href="?s='.($i+1).'">'.($i+1).'</a> ';
  21. }
  22. }
  23.  
  24. ?>


Ten post edytował altruista2 17.02.2010, 18:42:53
Go to the top of the page
+Quote Post
Bitkosa
post
Post #4





Grupa: Zarejestrowani
Postów: 31
Pomógł: 0
Dołączył: 21.10.2009

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


Dzięki (IMG:style_emoticons/default/snitch.gif) poradziłem sobie
Go to the top of the page
+Quote Post

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: 22.08.2025 - 12:30