Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Stronicowanie - działa ale wymaga drobnej zmiany, Co zrobić aby nie pokazywało linków g wyniki mieszczą się na 1 stronie
ikono
post 9.02.2010, 23:06:29
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 9.02.2010

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


Witam,

Wiem że to błahy problem ale raczkuję w temacie i sam sobie nie mogę poradzić. Co zrobić aby linki paginacji nie wyświetlały się gdy wyniki wyszukiwania zmieszczą się na pierwszej stronie.
Proszę o pomoc!

  1. <?php
  2. // database connection info
  3. $conn = mysql_connect(' ',' ',' ') or trigger_error("SQL", E_USER_ERROR);
  4. $db = mysql_select_db(' ',$conn) or trigger_error("SQL", E_USER_ERROR);
  5.  
  6. // find out how many rows are in the table
  7. $sql = "SELECT * FROM tabela";
  8. $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
  9. $r = mysql_fetch_row($result);
  10. $numrows = $r[0];
  11.  
  12. // number of rows to show per page
  13. $rowsperpage = 2;
  14.  
  15. // find out total pages
  16. $totalpages = ceil($numrows / $rowsperpage);
  17.  
  18.  
  19. // get the current page or set a default
  20. if (isset($_GET['podstrona']) && is_numeric($_GET['podstrona'])) {
  21. // cast var as int
  22. $podstrona = (int) $_GET['podstrona'];
  23. } else {
  24. // default page num
  25. $podstrona = 1;
  26. } // end if
  27.  
  28. // if current page is greater than total pages...
  29. if ($podstrona > $totalpages) {
  30. // set current page to last page
  31. $podstrona = $totalpages;
  32. } // end if
  33. // if current page is less than first page...
  34. if ($podstrona < 1) {
  35. // set current page to first page
  36. $podstrona = 1;
  37. } // end if
  38.  
  39. // the offset of the list, based on current page
  40. $offset = ($podstrona - 1) * $rowsperpage;
  41.  
  42. // get the info from the db
  43. $sql = "SELECT * FROM tabela WHERE nazwa LIKE '".$nazwa."%'
  44.  
  45. AND jednorodzinne LIKE '".$jednorodzinne."%' ORDER BY id ASC LIMIT $offset, $rowsperpage";
  46.  
  47. $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
  48.  
  49. // while there are rows to be fetched...
  50. while ($list = mysql_fetch_assoc($result)) {
  51. // echo data
  52.  
  53.  
  54.  
  55. echo '<ul align="center" style="width:540px; list-style:none; list-style-type:none; margin:0; padding-left:20;">';
  56.  
  57.  
  58.  
  59.  
  60.  
  61. echo '<li style="float:left; width:250px; height:220px; margin:0; padding:10;">
  62.  
  63.  
  64.  
  65. <a href="'.$list[link].'"rel="gb_pageset[search_sites]">'.$list[nazwa].'</a>
  66.  
  67. ';
  68. }
  69.  
  70. ?>
  71. </div>
  72.  
  73. <div style="float: left; margin: 5px; padding-left:20px;">
  74. <table align="center"><tr><td class="linkPaginacja">
  75. <?php
  76.  
  77.  
  78.  
  79. $range = 3;
  80.  
  81. // if not on page 1, don't show back links
  82. if ($podstrona > 1) {
  83.  
  84. // show << link to go back to page 1
  85. echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=1'>[<<]</a> ";
  86. // get previous page num
  87. $prevpage = $podstrona - 1;
  88. // show < link to go back to 1 page
  89. echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$prevpage'>poprzednia</a> ";
  90. } // end if
  91.  
  92. // loop to show links to range of pages around current page
  93. for ($x = ($podstrona - $range); $x < (($podstrona + $range) + 1); $x++) {
  94. // if it's a valid page number...
  95. if (($x > 0) && ($x <= $totalpages)) {
  96. // if we're on current page...
  97. if ($x == $podstrona) {
  98. // 'highlight' it but don't make a link
  99. echo '<b class="pusty_linkP">' . " [$x] " . '</b>';
  100. // if not current page...
  101. } else {
  102. // make it a link
  103. echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$x'>$x</a> ";
  104. } // end else
  105. } // end if
  106. } // end for
  107.  
  108. // if not on last page, show forward and last page links
  109. if ($podstrona != $totalpages) {
  110. // get next page
  111. $nextpage = $podstrona + 1;
  112. // echo forward link for next page
  113. echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$nextpage'>następna</a> ";
  114. // echo forward link for lastpage
  115. echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$totalpages'>[>>]</a> ";
  116.  
  117. } // end if
  118.  
  119.  
  120.  
  121.  
  122.  
  123. /****** end build pagination links ******/
  124. ?>
  125.  
  126.  
  127.  
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.06.2025 - 20:13