PHP: Trying to come up with a "prev" and "next" link

Posted by fwaokda on Stack Overflow See other posts from Stack Overflow or by fwaokda
Published on 2011-01-11T20:48:57Z Indexed on 2011/01/11 20:54 UTC
Read the original article Hit count: 115

Filed under:
|
|

I'm displaying 10 records per page. The variables I have currently that I'm working with are..

$total = total number of records
$page  = whats the current page I'm displaying

I placed this at the top of my page...

if ( $_GET['page'] == '' ) { $page = 1; } //if no page is specified set it to `1`
else { $page = ($_GET['page']); }  // if page is specified set it

Here are my two links...

    if ( $page != 1 ) { echo '<div style="float:left" ><a href="index.php?page='. ( $page - 1 ) .'" rev="prev" >Prev</a></div>'; }     
    if ( !( ( $total / ( 10 * $page ) ) < $page ) ) { echo '<div style="float:right" ><a href="index.php?page='. ( $page + 1 ) .'" rev="next" >Next</a></div>'; }

Now I guess (unless I'm not thinking of something) that I can display the "Prev" link every time except when the page is '1'. How can make it where the "Next" link doesn't show on the last page though?

© Stack Overflow or respective owner

Related posts about php

Related posts about math