Skip to content
Snippets Groups Projects
Commit 8b7f4011 authored by Tran Le's avatar Tran Le
Browse files

fixed displaying an entry. list of entries displaying in reverse order and has...

fixed displaying an entry. list of entries displaying in reverse order and has post number beside title
parent 3e36d0cb
Branches
No related merge requests found
...@@ -7,15 +7,16 @@ ...@@ -7,15 +7,16 @@
$entryTable = new Blog_Entry_Table($pdo); $entryTable = new Blog_Entry_Table($pdo);
//Showing individual entry: //Check that the user has clicked on an entry 'id'
//check that the user has clicked on an entry 'id' //if so, show that entry and its contents
$entryClicked = isset($_GET['id']); $entryClicked = isset($_GET['id']);
if($entryClicked) { if($entryClicked) {
$entryId = $_GET['id']; $entryId = $_GET['id'];
$entryData = $entryTable->getEntry( $entryId ); $entryData = $entryTable->getEntry( $entryId );
include_once "views/entry-html.php"; include_once "views/entry-html.php";
} }
//if not, display the list of all entries (in reverse chronological order)
else { else {
$entries = $entryTable->getAllEntries(); $entries = $entryTable->getAllEntries();
include_once "views/list-entries-html.php"; include_once "views/list-entries-html.php";
......
...@@ -12,7 +12,7 @@ class Blog_Entry_Table extends Table { ...@@ -12,7 +12,7 @@ class Blog_Entry_Table extends Table {
//Get all entries //Get all entries
public function getAllEntries () { public function getAllEntries () {
$entrySQL = "SELECT id, title, SUBSTRING(text, 1, 140) AS intro FROM blog_entry"; $entrySQL = "SELECT id, title, SUBSTRING(text, 1, 140) AS intro FROM blog_entry ORDER BY id DESC";
//SELECT 'columnName' AS 'aliasName' //SELECT 'columnName' AS 'aliasName'
//this is SQL Aliases: temporarily rename a table or column heading as 'intro' //this is SQL Aliases: temporarily rename a table or column heading as 'intro'
//so that it's more readable. //so that it's more readable.
......
...@@ -7,18 +7,26 @@ ...@@ -7,18 +7,26 @@
trigger_error('views/entry-html.php needs an $entryData object'); trigger_error('views/entry-html.php needs an $entryData object');
} }
//echo out the title, entry and date created //Display title, entry and date created of an entry
$content = "<article>
<h3>Blog entries: </h3>
<img src='uploads/totoro.jpg' height='130' width='130'/>
<h1>$entryData->title</h1>
<pre>$entryData->text</pre>
<div class='date'>Created on: $entryData->date_created</div>
</article>";
$content = "<br/>";
$content = "<a href='http://doc.gold.ac.uk/~tle004/dnw/coursework-blog-tle004/index.php'>Back</a>";
echo $content;
echo "<article>
<h1>$entryData->title</h1>
<h3>Post $entryData->id</h3>
<br/>
<pre>$entryData->text</pre>
<br/>
<div id='entry-author'>
<p>Posted by: tle004</p>
<img src='uploads/bart-simpson.png' height='80' width='80'/>
<p class='date'>Posted on: $entryData->date_created</p>
</div>
</article>";
$entry = "<br/>";
$entry = "<a href='http://doc.gold.ac.uk/~tle004/dnw/coursework-blog-tle004/index.php'> << Back </a>";
echo $entry;
?> ?>
\ No newline at end of file
...@@ -11,15 +11,16 @@ ...@@ -11,15 +11,16 @@
$entriesHTML = "<ul id='blog-entries'>"; $entriesHTML = "<ul id='blog-entries'>";
while ($entry = $entries->fetchObject()) { //Loop over all the blog entries while ($entry = $entries->fetchObject()) { //Loop over all the blog entries
//for each entry, echo out the title and first 140 characters
//for each entry, display the entry number, title, first 140 characters
//entries are displayed in reverse chronological order
//a link for 'Read more' which uses the entry 'id' to tell the blog controller //a link for 'Read more' which uses the entry 'id' to tell the blog controller
//to display only that entry //to display only that entry
$readmoreLink = "index.php?page=blog&amp;id=$entry->id"; $readmoreLink = "index.php?page=blog&amp;id=$entry->id";
$entriesHTML .= "<li> $entriesHTML .= "<li>
<img src='uploads/bart-simpson.png' height='100' width='100'/> <img src='uploads/bart-simpson.png' height='100' width='100'/>
<h2>$entry->title</h2> <h2>Post $entry->id: $entry->title</h2>
<p>$entry->intro</p> <p>$entry->intro</p>
<p><a href='$readmoreLink'>Read more</a></p> <p><a href='$readmoreLink'>Read more</a></p>
</li>"; </li>";
......
...@@ -11,7 +11,12 @@ $search_form = "<form action='".$action."' method='POST'> ...@@ -11,7 +11,12 @@ $search_form = "<form action='".$action."' method='POST'>
<input type='text' id='usersearch' name='usersearch' /> <input type='text' id='usersearch' name='usersearch' />
".$searchField." ".$searchField."
<button type='submit' value='search'> Start Search </button> <button type='submit' value='search'> Start Search </button>
</form>"; <div>(e.g. Hello)</div>
</form>
<br/>
<br/>";
// ------- START form processing code ------- // ------- START form processing code -------
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment