php - pagination count range of products on current page -
the pagination here works fine, addition pagination, limit per page 3 suppose total 8 items in database want display " showing 1 t0 3 item of 8" on page one, "showing 4 6 items of 8" on page 2 , on. please help
$recordslimit = 3; $page = isset($_get['page']) ? intval($_get['page']): 1; $totalproducts = countproducts($selectedcategoryid); $totalpages = ceil($totalproducts / $recordslimit); $pagenumber = $recordslimit * ($page - 1); $products = getproductsbycatid($selectedcategoryid, $pagenumber, $recordslimit); <?php if($totalproducts > $recordslimit) : ?> <div class="pagination"> <span>page <?php echo $page.' of '.$totalpages; ?></span> <?php for($i=1; $i <= $totalpages; $i++) : if($i == $page) { ?> <strong><?php echo $i; ?></strong> <?php } else { ?> <a href="products.php?cat_id=<?php echo $selectedcategoryid; ?>&page=<?php echo $i; ?>"><?php echo $i; ?></a> <?php } endfor; ?> <?php endif; ?>
try:
echo "showing ".( $page == 1 ? 1 : ($page -1) * $recordslimit +1 )." ".($page * $recordslimit)." item of ".$totalproducts;
Comments
Post a Comment