FaaPz/PDO

Pagination Problem

Closed this issue · 0 comments

Currently building a pagination class and i´m having a tiny problem. The first page looks fine but when i go to page 2 the rows has the same data -1 row from the top.

Old

$stmt = $this->pdo->select()->from( $this->table ); $currPage = $_GET['currPage']; $stmt = $stmt->limit(5, (int)$currPage ); $stmt = $stmt->execute(); $data = $stmt->fetchall();

Solution

`
$stmt = $this->pdo->select()->from( $this->table );
$currPage = $_GET['currPage'];
$limit = 5;
$offset = $limit;
$row = $limit;

if ($currPage == 1) {
    $offset = $limit ;
    $row 	= 0;
}else{
    $offset = ($offset * $currPage);
    $row 	= ($row * $currPage - $limit );
}
$stmt  		= $stmt->limit( (int)$offset , (int)$row );
$stmt  		= $stmt->execute();
$data  		= $stmt->fetchall();

`