简体   繁体   中英

not to show previous link at the start page and next link at the last page?

I have to links Next and Previous in Pagination. What I should do so that 'previous' link should hide when I was on the first page and the 'next' link should hide when I was on the last page? my code for next and previous links is:

echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page-1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Previous</a>';

echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page+1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Next</a>';

It wont work well the way your doing it right now, unless you have the specific number of pages.

If you have the total number of pages, you can do this

if( $page > 1 ) {
 echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page-1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Previous</a>';
}
if( $page < $totalPages ) {
 echo '<a href="'.$_SERVER['PHP_SELF'].'?page='
.($page+1).'&date1='.$_REQUEST["date1"].'&date2='.$_REQUEST["date2"].'">Next</a>';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM