Soldato
- Joined
- 22 Aug 2005
- Posts
- 8,969
- Location
- Clydebank
Hi there - was having probs eariler with MysQL iming out and stuff, but as I progressed I foudn the way, and now I only query what I'm using per page.
I wrote this code for pagination, but is it possible to reverse the logic, so I don't have the big chunks of GET to describe the page links?
Also, anyone done anything neat with a pagination system that they want to share?
Produces a result like this:
Page: << < 1 401 451 476 496 497 498 499 500 501 502 503 504 505 506 526 551 601 1001 > >>
Total of: 1827 pages.
Cheers all
I wrote this code for pagination, but is it possible to reverse the logic, so I don't have the big chunks of GET to describe the page links?
Also, anyone done anything neat with a pagination system that they want to share?
PHP:
//PAGINATION
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }
// one day per page
$total_pages = count($daterange);
if ( $total_pages<$page ) { $page = $total_pages; }
echo "<P><hr>";
echo "Page: ";
echo "<a href=reportlist.php?page=1&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"><<</a> ";
$prev_page = $page-1;
if ($prev_page == 0) { $prev_page=1; }
echo "<a href=reportlist.php?page=".$prev_page."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"><</a> ";
for ($i=1; $i<=$total_pages; $i++) {
if ($i == $page ) echo "<big><b>";
if ( $i - 500 == $page || $i + 500 == $page ) {
echo "<a href=reportlist.php?page=".$i."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"> ".$i." </a> ";
} elseif ( $i - 100 == $page || $i + 100 == $page ) {
echo "<a href=reportlist.php?page=".$i."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"> ".$i." </a> ";
} elseif ( $i - 50 == $page || $i + 50 == $page ) {
echo "<a href=reportlist.php?page=".$i."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"> ".$i." </a> ";
} elseif ( $i - 25 == $page || $i + 25 == $page ) {
echo "<a href=reportlist.php?page=".$i."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
"> ".$i." </a> ";
} elseif ( $page + 5 < $i || $page - 5 > $i ) {
// do nothing
} else {
echo "<a href=reportlist.php?page=".$i."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
">".$i."</a> ";
}
if ($i == $page ) echo "</b></big>";
};
$next_page = $page+1;
if ($next_page > $total_pages) { $next_page=$total_pages; }
echo "<a href=reportlist.php?page=".$next_page."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
">></a> ";
echo "<a href=reportlist.php?page=".$total_pages."&report=".$report_code.
'&year_select_start='. $_GET['year_select_start'] .
'&month_select_start='. $_GET['month_select_start'] .
'&date_select_start='. $_GET['date_select_start'] .
'&year_select_end='. $_GET['year_select_end'] .
'&month_select_end='. $_GET['month_select_end'] .
'&date_select_end='. $_GET['date_select_end'].
">>></a>";
echo "<br />Total of: ".$total_pages." pages.";
Produces a result like this:
Page: << < 1 401 451 476 496 497 498 499 500 501 502 503 504 505 506 526 551 601 1001 > >>
Total of: 1827 pages.
Cheers all