public $day_posted;
public $text;
public $number_of_comments;
+ public $comments;
public function __construct() {
parent::__construct();
}
public function display_comments() {
- echo "<div id='comments'>";
+ // should be called like $note->comment[0]['author']
$sql= "SELECT date_posted, author, text
FROM comments WHERE note = ?
ORDER BY date_posted DESC";
$result = $this->query($sql, 'd', $this->id);
+ $i = 0;
foreach ($result as $row => $entry) {
- $date_posted = $entry['date_posted'];
- $author = $entry['author'];
- $text = htmlspecialchars($entry['text']);
- $head = "<h3>" . htmlspecialchars($author) . "</h3>";
- echo "<div class='comment'>";
- echo $head;
- echo $text;
- echo "</div>";
+ $this->comment[$i]['date_posted'] = $entry['date_posted'];
+ $this->comment[$i]['author'] = $entry['author'];
+ $this->comment[$i]['text'] = htmlspecialchars($entry['text']);
+ $this->comment[$i]['head'] = "<h3>" . htmlspecialchars($author) . "</h3>";
+ $i++;
}
- echo "</div>";
}
public function display_comment_form() {
public $offset = 0;
public $notes_per_page = 4;
public $number_of_pages = 1;
+ public $notes = array();
public function __construct() {
parent::__construct();
$this->page_offset();
+ $this->fetch_notes();
}
private function page_offset() {
require_once("view/page.php");
}
- public function display_notes() {
- echo "<div id='notes'>";
+ protected function fetch_notes() {
$sql = "SELECT date_posted, title, url, text
FROM notes ORDER BY date_posted DESC
LIMIT ?, ?";
$this->offset,
$this->notes_per_page);
foreach ($result as $row => $entry) {
- $title = $entry['title'];
- $url = '/note/' . $entry['url'];
- $date_posted = explode("-", $entry['date_posted']);
- $year_posted = $date_posted[0];
- $month_posted = $date_posted[1];
- $datetime_posted = explode(' ', $date_posted[2]);
- $day_posted = $datetime_posted[0];
- $text = $entry['text'];
- echo <<<END_NOTE
- <div class='note'>
- <h1>
- <span class='date'>$year_posted/$month_posted/$day_posted/</span><a rel="canonical" href='$url'>$title</a>
- </h1>
- $text
- </div>
-END_NOTE;
+ $entry['url'] = '/note/' . $entry['url'];
+ $date_posted = explode("-", $entry['date_posted']);
+ $entry['year_posted'] = $date_posted[0];
+ $entry['month_posted'] = $date_posted[1];
+ $entry['datetime_posted'] = explode(' ', $date_posted[2]);
+ $entry['day_posted'] = $entry['date_posted'][0];
+ $this->notes[$row] = $entry;
}
- echo "</div>";
}
}
</div>
<div id="content">
- <div id='notes'>
- <?php $this->display_notes() ?>
+ <div id="notes">
+ <div id="notes">
+ <?php
+ foreach ($this->notes as $note) {
+ echo "<div class='note'>";
+ echo "<h1>";
+ echo "<span class='date'>";
+ echo $note['year_posted'] . "/";
+ echo $note['month_posted'] . "/";
+ echo $note['day_posted'] . "/";
+ echo "</span>";
+ echo "<a href='" . $note['url'] . "'>";
+ echo $note['title'];
+ echo "</a>";
+ echo "</h1>";
+ echo $note['text'];
+ }
+ ?>
+ </div>
<div id='navigation'>
<h1>
<?php