sometimes last year i went through a php mvc tutorial done by jream the platform looks so simple and convenient. Now am building a web application with this mvc platform and now am stoked in the aspect of pagination, while trying to paginate records from the PDO database.
source codes below.
model:
function paginate() {
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$perPage = isset($_GET['per-page']) && $_GET['per-page'] <= 50 ? (int) $_GET['per-page'] : 5;
$start=($page > 1) ? ($page * $perPage) - $perPage :0;
$articles = $this->db->prepare("Select SQL_CALC_FOUND_ROWS id,title from tblpost limit {$start},{$perPage}");
$articles->execute();
$articles = $articles->fetchAll(PDO::FETCH_ASSOC);
$total = $this->db->query("SELECT FOUND_ROWS() as total")->fetch() ['total'];
return $pages = ceil($total / $perPage);
}
controller:
function index() {
$this->view->title = "Home";
$this->view->home = $this->model->loadpost();
$this->view->pgcount= $this->model->paginate();
$this->view->render("index/index");
}
view:
<div>
<?php for($x=1;$x <= $pages; $x++): ?>
<a href="#"><?php echo $x;?></a>
<?php endfor; ?>
</div>
i need to make the post paginate using this particular php mvc