Example #1
0
    function readAll($page, $from_record_num, $records_per_page)
    {
        $query = "SELECT * FROM tbl_ut_user LIMIT  {$from_record_num}, {$records_per_page}";
        $stmt = $this->conn->prepare($query);
        $stmt->execute();
        return $stmt;
    }
}
// page given in URL parameter, default page is one
$page = isset($_GET['page']) ? $_GET['page'] : 1;
// set number of records per page
$records_per_page = 5;
// calculate for the query LIMIT clause
$from_record_num = $records_per_page * $page - $records_per_page;
$pag = new Pagination();
$stmt = $pag->readAll($page, $from_record_num, $records_per_page);
$num = $stmt->rowCount();
// display the products if there are any
if ($num > 0) {
    echo "<table class='table table-hover table-responsive table-bordered'>";
    echo "<tr>";
    echo "<th>Product</th>";
    echo "</tr>";
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        extract($row);
        echo "<tr>";
        echo "<td>{$name1}</td>";
        echo "</tr>";
    }
    echo "</table>";
    // paging buttons will be here