Hi there!
I'm coding a page with a list, and I need to divide it into several pages. to do
last page <this pagenumber> next page
is simple, but I want to do like this:
last page 1 2 3 4 5 next page
so it shows X pages in the list, so, if there are 25 pages, it still shows the 5 (2 before, 2 after and current).
I got it working for everything butnot in front or back of the pageset, as if viewing first page, we'll still show page 1 2 3 4 5
even if there aren't 2 before and 2 after. ofcourse the same in the end.
as I also use smarty document templates, I need to put the info into an array for easiest coding
at the moment, I do like this
function prev_next_page($rows, $limit, $start) {
if ($rows > $limit) {
//count how many pages we must have
$pages=intval($rows/$limit);
//check if we need another page for the result
if ($rows%$limit) {
$pages++;
}
//should we show the prev button
if ($start !=0) {
$newstart = $start-$limit;
//assign the smarty variables
$smarty->assign("s_SHOWPREV", 1);
$smarty->assign("s_SHOWPREV_NEWSTART", $newstart);
}
$showpages = 7; // must be uneven!!
$showsidepages = ($showpages-1)/2;
$ii = 0;
//print out the page numbers
for ($i=1;$i<=$pages;$i++) {
//check what page we are on
$page = ($start/$limit)+1;
//it's this part I'd need help with to make the logic work
if (
( ($i >= $page-$showsidepages) && ($i <= $page+$showsidepages) ) ||
( ($i-$showsidepages >= 0 ) && ($i < $page ) ) ||
( ($pages-$i+1 <=$pages+1 ) && ($i > $page ) )
) {
//build the value of the next start value
$newstart=$limit*($i-1);
//set up the array that should be sent to smarty
$pnum[$ii][pagenum] = $i; // printed num
$pnum[$ii][curpage] = $page; // same on all
$pnum[$ii][link] = $link; // link
$pnum[$ii][newstart] = $newstart; // startsize of the pagenum
$ii++;
}
}
//should we show the next button
if (!((($start+$limit)/$limit) >= $pages)) {
$newstart = $start+$limit;
//assign the smarty variables
$smarty->assign("s_SHOWNEXT", 1);
$smarty->assign("s_SHOWNEXT_NEWSTART", $newstart);
}
//assign the smarty variables
$smarty->assign("s_PAGE", $pnum);
}
}
any suggestions? tried to search the web, but I couldn't find a good word to seache for that had good results....
please? thanks in advance!