Exemplo n.º 1
0
<?php

require_once "includes/initialize.php";
if (!$session->is_logged_in()) {
    redirect_to("login.php");
}
?>
 <?php 
// 1. the current page number ($current_page)
$page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
// 2. records per page ($per_page)
$per_page = 10;
// 3. total record count ($total_count)
$total_count = Assignment::count_all();
//4. to limit pagination number
// 3 means abc[page]efg -> 3 right, 3 left
$stages = 2;
$pagination = new Pagination($page, $per_page, $total_count);
// Instead of finding all records, just find the records
// for this page
$sql = "SELECT * FROM assignments  ";
if (isset($_POST['sort'])) {
    $batch = strtolower($_POST['batch']);
    $sql .= "WHERE batch={$batch}";
}
$sql .= "ORDER BY created DESC ";
$sql .= " LIMIT {$per_page} ";
$sql .= "OFFSET {$pagination->offset()} ";
$assignments = Assignment::find_by_sql($sql);
if (empty($assignments)) {
    $session->message("There are no Assignments in Assignment vault.");