$limit = 2; $total_pages = ceil($total/ $limit); $page = max($page, 1); $page = max($page, $total_pages); echo "PAGE RES ".$page; $offset = min($page, - 1) * $