In other words, I presume you mean that
in
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href='$PHP_SELF?page=$pagenext'>NEXT</a>");
}else{
echo"NEXT";
}
$totalrows - ($limit*$page) is never > 0.
One problem you have is that
$pagenext = $page++;
won't make $pagenext equal to $page+1. You want
$pagenext = $page+1;
there. Similarly for previous pages.
Lessee:
$totalrows - ($limit*$page) > 0
$totalrows > $limit*$page
$totalrows/$limit > $page
$numofpages > $page
Okay... so the test will fail if the number of pages is equal to or fewer than the current page (presumably equal to, though you never can tell with some people).
And $numof pages will be the problem. $totalrows is always going to equal 1, because exactly one row will be returned from the query "SELECT COUNT(*)" - one row with one record containing the number you're actually after. And if $totalrows==1, then $numofpages is going to be 0.5, which is definitely less than 1, so the test fails.