3 class page
extends model
{
7 public $notes_per_page = 4;
8 public $number_of_pages = 1;
9 public $notes = array();
11 public function __construct() {
12 parent
::__construct();
17 private function page_offset() {
18 $sql = "SELECT COUNT(*) FROM notes";
19 $result = $this->db
->query($sql);
20 $result = $result->fetch_array();
21 $this->number_of_pages
= ceil($result[0] / $this->notes_per_page
);
22 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
23 $this->page
= (int) $_GET['page'];
27 if ($this->page
> $this->number_of_pages
) {
30 if ($this->page
< 1) {
33 $this->offset
= ($this->page
- 1) * $this->notes_per_page
;
36 public function display() {
37 require_once("view/page.php");
40 protected function fetch_notes() {
41 $sql = "SELECT date_posted, title, url, text
42 FROM notes ORDER BY date_posted DESC
44 $result = $this->query($sql, "ii",
46 $this->notes_per_page
);
47 foreach ($result as $row => $entry) {
48 $entry['url'] = '/note/' . $entry['url'];
49 $date_posted = explode("-", $entry['date_posted']);
50 $entry['year_posted'] = $date_posted[0];
51 $entry['month_posted'] = $date_posted[1];
52 $entry['datetime_posted'] = explode(' ', $date_posted[2]);
53 $entry['day_posted'] = $entry['date_posted'][0];
54 $this->notes
[$row] = $entry;