Basically I am trying to get last page... And well it works sometimes but then say some data is entered in then it gets the wrong page and more data is entered then right page will appear I am pretty sure it has something to do with the $r part. Theres more to it but uh this is the main part. I think I am just using wrong math or functions please help.
$limit = 10;
if($_GET['page'] == 0 OR $_GET['page'] == 1) {
$offset = 0;
} else {
$offset = $limit * $_GET['page'] - $limit;
}
$next = $_GET['page'] + 1;
$back = $_GET['page'] - 1;
$stmt = $db->prepare("SELECT * FROM users");
$stmt->execute();
$count = $stmt->rowCount();
if($count < $limit) {
$last = 1;
}
$r = $count % $limit;
if($r < 5) {
$last = ceil($count / $limit);
} else {
if($r >= 5) {
$last = floor($count / $limit);
}
}
if($_GET['page'] == 0 or $_GET['page'] == 1) {
if (0 >= $last) {
$page = 0;
}
if (1 >= $last) {
$page = 1;
}
}