Jak stworzyć stronicowanie do tego?

  1. <?
  2. require 'config.php';
  3. require_once 'user.class.php';
  4. require_once ('szkielet.php');
  5. ?>
  6.  
  7. <span style="color:white;"><div class="main box_black"><span style="color:white;"><center><? $listaid = mysql_query("SELECT * FROM newsy WHERE `stan` = '1' order by dataa DESC limit 5");
  8. echo "<center>";
  9. ?><span style="color:white;"><?
  10. echo"<table cellpadding=\"2\" border=1>";
  11. while($r = mysql_fetch_assoc($listaid)) {
  12. if($r['typ'] == "YoueTube"){
  13. ?>
  14.  
  15. <div class="btn_green">
  16. <a href="czytaj.php?id=<?echo$r[id];?>"><? echo" $r[tytul]</h1></a></b>"; if($user['admin'] == 1){ ?><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:green">AKCEPTUJ</span></a><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:red">USUŃ</span></a><?}?></center></td><br> </ul>
  17. </nav>
  18. </div>";
  19. ?><div class="btn_green"><? echo "<td><center> "; ?><b style="color:white;"><? echo"$r[tresc]</b></div><br>"; ?><div class="g-plusone" data-annotation="inline" data-width="300"></div> <!-- Umieść ten tag po ostatnim tagu widżetu przycisk +1. --> <script type="text/javascript"> window.___gcfg = {lang: 'pl'}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fpileczka.xaa.pl&width&layout=button_count&action=like&show_faces=true&share=true&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
  20. </td></center> <?
  21.  
  22. echo "<td><center> <b><i>"; ?><span style="margin-left:800px; color:white;"><? echo"$r[autor]</span></i></b></center></td><br>";
  23.  
  24.  
  25. }
  26. if($r['typ'] == "Zdjeecie"){
  27. ?>
  28. <div class="btn_green">
  29. <a href="czytaj.php?id=<?echo$r[id];?>"><? echo" $r[tytul]</h1></a></b>"; if($user['admin'] == 1){ ?><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:green">AKCEPTUJ</span></a><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:red">USUŃ</span></a><?}?></center></td><br> </ul>
  30. </nav>
  31.  
  32.  
  33. </div><?
  34. ?><div class="btn_green"><? echo "<td><center> "; ?><img src="<?echo"$r[tresc]";?>"></div><br><div class="g-plusone" data-annotation="inline" data-width="300"></div> <!-- Umieść ten tag po ostatnim tagu widżetu przycisk +1. --> <script type="text/javascript"> window.___gcfg = {lang: 'pl'}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fpileczka.xaa.pl&width&layout=button_count&action=like&show_faces=true&share=true&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
  35. </td></center>
  36. <?
  37. echo "<br><br><br><br><br><br><br><br><br><br><br><br><br><td><center> <b><i>"; ?><span style="margin-left:500px; color:white;"><? echo"$r[autor]</span></i></b></center></td><br>";
  38. }
  39. if($r['typ'] == "Tekest"){
  40. ?>
  41. <div class="btn_green">
  42. <a href="czytaj.php?id=<?echo$r[id];?>"><? echo" $r[tytul]</h1></a></b>"; if($user['admin'] == 1){ ?><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:green">AKCEPTUJ</span></a><a href="poczekalnia.php?id=<? echo''.$_GET[id].''; ?>&akcja=usun&idd=<? echo''.$r['id'].''; ?>"><span style="color:red">USUŃ</span></a><?}?></center></td><br> </ul>
  43. </nav>
  44. </div>";
  45. ?><div class="btn_green"><? echo "<td><center> "; ?><b style="color:white;"><? echo"$r[tresc]</b></div><br>"; ?><div class="g-plusone" data-annotation="inline" data-width="300"></div> <!-- Umieść ten tag po ostatnim tagu widżetu przycisk +1. --> <script type="text/javascript"> window.___gcfg = {lang: 'pl'}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fpileczka.xaa.pl&width&layout=button_count&action=like&show_faces=true&share=true&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe>
  46. </td></center> <?
  47. echo "<td><center> <br><br><b><i>"; ?><span style="margin-left:800px; color:white;"><? echo"$r[autor]</span></i></b></center></td><br>";
  48. }
  49.  
  50. echo "<tr>"; ?><!-- ExAd.me | 468x60 | --> <script type="text/javascript" src="http://468x60.exad.me/js/?id=4693"></script> <? echo "<td><center> <b><h1> "; ?> <div class="btn_green"> <a href="czytaj.php?id=<?echo$r[id];?>"><? echo" $r[tytul]</h1></a></b></center></td><br> </ul> </nav> </div> </div> </footer>"; echo "</tr>"; ?><span style="color:white;"><? echo "<tr>"; ?><div class="btn_green"><? echo "<td><center> "; ?><b style="color:white;"><?
  51.  
  52. if($r['typ'] == "Zdjecie"){
  53. ?><img src="<?echo"$r[tresc]";?>"></b></div><br><?
  54. } elseif($r['typ'] == "YouTube"){
  55. preg_match('#(.*)watch\?v=(.+)#',$r['tresc'],$matches);
  56. $video_id = $matches[2];
  57. $embed = 'http://youtube.com/embed/'.$video_id;
  58. ?>
  59. <iframe width="560" height="315" src="<? echo"$embed"; ?>" frameborder="0" allowfullscreen></iframe>
  60. </b></div><br><?
  61. } else {
  62. echo"$r[tresc]</b></div><br>"; }?>
  63.  
  64. <div class="g-plusone" data-annotation="inline" data-width="300"></div> <!-- Umieść ten tag po ostatnim tagu widżetu przycisk +1. --> <script type="text/javascript"> window.___gcfg = {lang: 'pl'}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'http://pileczka.xaa.pl/czytaj.php?id=<?echo"$r[id]";?>'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script> <iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fpileczka.xaa.pl/czytaj.php?id=<?echo"$r[id]";?>&width&layout=button_count&action=like&show_faces=true&share=true&height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; height:21px;" allowTransparency="true"></iframe> </td></center> <? echo "</tr>"; echo "<tr></span>"; echo "</tr>"; echo "<tr></center>"; ?><!-- Umieść ten tag w miejscu, w którym ma być widoczny przycisk +1. --> <br><? ?><? echo "<td><center> <b><i>"; ?><span style="margin-left:800px; color:white;"><? echo"$r[autor]</span></i></b></center></td><br>"; ?> <? echo "</tr>";
  65.  
  66. ?><? }
  67. echo "</table>";
  68. echo "</center>"; ?>
  69.  
  70. </b></center></span></div></span>
  71. <?php
  72. require_once ('stopka.php');
  73. ?>
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  



Mam taki kodzik na stronicowanie:
  1. <?php
  2. $count=1; //wyników na strone
  3. $offset=0; //obecnie wyświetlana strona
  4.  
  5. if(isset($_GET['count'])) //jeśli wybrano za pomocą GET ilość wyników
  6. {
  7. $count = $_GET['count'];
  8. }
  9. if(isset($_GET['offset'])) //jeśli wybrano kolejne strony z wynikami
  10. {
  11. $offset = $count*$_GET['offset'];
  12. }
  13.  
  14. // zapytanie zwracające ilosc rekordów z tabeli
  15. $sql = 'SELECT COUNT(*) FROM `newsy`';
  16. $result = mysql_query($sql);
  17. $r = mysql_fetch_array($result);
  18. //podział wyników na strony
  19. $pages = ceil($r[0]/$count);
  20. //wybranie wyników dla bieżących parametrów offset
  21. $select = 'SELECT * FROM `newsy` ORDER BY `id` desc LIMIT '.$count.' offset '.$offset.';';
  22.  
  23.  
  24. $q=mysql_query($select)or die(mysql_error());
  25. while($row=mysql_fetch_array($q))
  26. {
  27. //wyświetlanie rekordów z tabeli za pomocą zmiennej $row
  28. }
  29.  
  30.  
  31. echo "<b>kolejne strony</b>";
  32.  
  33. for($i=0;$i<$pages;$i++) //wyswietlanie numerów stron
  34. {
  35. if($i*$count==$offset)
  36. {
  37. echo ' '.$i.' ';
  38. }else{
  39. echo '<a href="index.php?count='.$count.'&offset='.$i.'"> '.$i.' </a>'; //tworzenie odnośnika z odpowiednimi parametrami offset i count
  40. }
  41. }
  42. ?>
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.