3 class page
extends model
{
7 public $notes_per_page = 4;
8 public $number_of_pages = 1;
10 public function __construct() {
11 parent
::__construct();
15 private function page_offset() {
16 $sql = "SELECT COUNT(*) FROM notes";
17 $result = $this->db
->query($sql);
18 $result = $result->fetch_array();
19 $this->number_of_pages
= ceil($result[0] / $this->notes_per_page
);
20 if (isset($_GET['page']) && is_numeric($_GET['page'])) {
21 $this->page
= (int) $_GET['page'];
25 if ($this->page
> $this->number_of_pages
) {
28 if ($this->page
< 1) {
31 $this->offset
= ($this->page
- 1) * $this->notes_per_page
;
34 public function display() {
35 require_once("view/page.php");
38 public function display_notes() {
39 echo "<div id='notes'>";
40 $sql = "SELECT date_posted, title, url, text
41 FROM notes ORDER BY date_posted DESC
43 $result = $this->query($sql, "ii",
45 $this->notes_per_page
);
46 foreach ($result as $row => $entry) {
47 $title = $entry['title'];
48 $url = '/note/' . $entry['url'];
49 $date_posted = explode("-", $entry['date_posted']);
50 $year_posted = $date_posted[0];
51 $month_posted = $date_posted[1];
52 $datetime_posted = explode(' ', $date_posted[2]);
53 $day_posted = $datetime_posted[0];
54 $text = $entry['text'];
58 <span class='date'>$year_posted/$month_posted/$day_posted/</span><a rel="canonical" href='$url'>$title</a>