Handling Entries for a Blogger Built with PHP - Creating the displayUpdateForm() method (
Page 4 of 5 )
Following a similar approach to the one that I used for creating the insertion form that you learned about in the previous section, it's possible to define another important method that belongs to the "BlogProcessor" class. This one displays the required online form for updating a specific blog entry.
This being said, the signature for this broadband new method, denominated "displayUdpateForm()" is the following:
// display update form
private function displayUpdateForm(){
$id=$this->blogData['id'];
$result=$this->mysql->query("SELECT * FROM blogs
WHERE id='$id'");
if($result->countRows()>0){
$row=$result->fetchRow();
$output=<<<EOD
<div class="dataform">
<h2>Update Blog</h2>
<form action="$_SERVER[PHP_SELF]" method="post" id="updateform">
<p>Title:</p><p><input type="text" name="title" value="$row
[title]" class="datafield" /></p>
<p>Author:</p><p><input type="text" name="author" value="$row
[author]" class="datafield" /></p>
<p>Update your content below</p><p><textarea name="content">$row
[content]</textarea></p>
<p><input type="submit" name="updateblog" value="Update
Blog" /></p>
<input type="hidden" value="$id" name="id" />
</form>
</div>
EOD;
return $output;
}
}
As you'll certainly appreciate, the definition of the new method is closely similar to "displayInsertForm()", which was covered in the section you just read. This new method simply displays the corresponding update web form where all its boxes has been previously populated with the data that corresponds to the entry being updated (hence the execution of the SELECT statement in the first lines of code).
With reference to the prior method in particular, the only thing worth noticing is the inclusion of a hidden box to store the respective ID of the blog entry being updated. Quite simple, isn't it?
All right, at this stage you hopefully grasped the logic that stands behind the "BlogProcessor" class, and you understand how it displays the complete list of blogs and shows the pair of web forms necessary for inserting new blogs and updating previous ones. Thus, the next step involved in the development of this extensible blog application rests on creating three additional methods. These will be responsible for displaying programmatically the different sections that compose the main web page of the blogger, that is the header, the primary area and finally the footer.
To learn how these useful methods will be created, be a bit more patient and read the following section. We're almost finished!