今回は、ページ右側の最近の更新の部分を実装する。
<div class="recent"> 最近の更新 </div>
を
<div class="recent"> <?php $this->ShowRecent(); ?> </div>
と変更し、ShowRecentメソッドを実行した結果を表示できるようにする。
ShowRecentの内容は下のように実装した。
private function ShowRecent() { if(!isset($this->db)) { $this->ConnectDB(); } if($this->db === FALSE) { $this->DBErrorDie(); } $sql = "select id, title from diary order by lastUpdate desc limit 10;"; $result = $this->db->query($sql); if($result === FALSE) { echo('db error'); return; } echo('最近の更新<br />'); foreach($result as $row) { echo("<a href='./?type=DispOne&id={$row['id']}'>{$row['title']}</a><br />"); } }
これで、最近の更新の実装ができた。