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!
<?php
// database connection info
// find out how many rows are in the table
$sql = "SELECT * FROM tabela";
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 2;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
// cast var as int
$podstrona = (int) $_GET['podstrona'];
} else {
// default page num
$podstrona = 1;
} // end if
// if current page is greater than total pages...
if ($podstrona > $totalpages) {
// set current page to last page
$podstrona = $totalpages;
} // end if
// if current page is less than first page...
if ($podstrona < 1) {
// set current page to first page
$podstrona = 1;
} // end if
// the offset of the list, based on current page
$offset = ($podstrona - 1) * $rowsperpage;
// get the info from the db
$sql = "SELECT * FROM tabela WHERE nazwa LIKE '".$nazwa."%'
AND jednorodzinne LIKE '".$jednorodzinne."%' ORDER BY id ASC LIMIT $offset, $rowsperpage";
// while there are rows to be fetched...
// echo data
echo '<ul align="center" style="width:540px; list-style:none; list-style-type:none; margin:0; padding-left:20;">';
echo '<li style="float:left; width:250px; height:220px; margin:0; padding:10;">
<a href="'.$list[link].'"rel="gb_pageset[search_sites]">'.$list[nazwa
].'</a>
';
}
?>
</div>
<div style="float: left; margin: 5px; padding-left:20px;">
<table align="center"><tr><td class="linkPaginacja">
<?php
$range = 3;
// if not on page 1, don't show back links
if ($podstrona > 1) {
// show << link to go back to page 1
echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=1'>[<<]</a> "; // get previous page num
$prevpage = $podstrona - 1;
// show < link to go back to 1 page
echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$prevpage'>poprzednia</a> "; } // end if
// loop to show links to range of pages around current page
for ($x = ($podstrona - $range); $x < (($podstrona + $range) + 1); $x++) {
// if it's a valid page number...
if (($x > 0) && ($x <= $totalpages)) {
// if we're on current page...
if ($x == $podstrona) {
// 'highlight' it but don't make a link
echo '<b class="pusty_linkP">' . " [$x] " . '</b>'; // if not current page...
} else {
// make it a link
echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$x'>$x</a> "; } // end else
} // end if
} // end for
// if not on last page, show forward and last page links
if ($podstrona != $totalpages) {
// get next page
$nextpage = $podstrona + 1;
// echo forward link for next page
echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$nextpage'>następna</a> "; // echo forward link for lastpage
echo " <a href='{$_SERVER['REQUEST_URI']}&podstrona=$totalpages'>[>>]</a> ";
} // end if
/****** end build pagination links ******/
?>