全ページ数のうち、ページ数を制限したい。
- 例:
1 2 3 4 5 6 >> out of 30
- 例 2:
<< 5 6 7 8 9 10 >> out of 30
これが私のコードです:
$page = !empty($_GET['page']) ? (int) $_GET['page'] : 1;
// records per page
$per_page = 5;
// total records in database
$total_count = Mp3_Model::count_all();
// instantating the $pagination
$pagination = new Pagination($page, $per_page, $total_count);
// find the records for this page
$sql = "SELECT * FROM mp3 ";
$sql .= " LIMIT {$per_page} ";
$sql .= " OFFSET {$pagination->offset()}";
$mp3s = Mp3_Model::find_by_sql($sql);
foreach ($mp3s as $mp3) {
echo $mp3->titlu;
}
これはページネーションです:
<?php
if ($pagination->total_pages() > 1) {
if ($pagination->has_previous_page()) {
echo '<li><a href="?page=' . $pagination->previous_page() . '">«</a></li>';
}
for ($i = 1; $i <= $pagination->total_pages(); $i++) {
echo '<li';
if ($_GET['page'] == $i) {
echo ' class="active"';
}
echo '><a href="' . URL . 'mp3?page=' . $i . '">' . $i . '</a></li>';
}
if ($pagination->has_next_page()) {
echo '<li><a href="?page=' . $pagination->next_page() . '">» </a></li>';
}
}
?>