All right, the parent class postparent is defined as an abstraction, and the subclass must implement the Buildhtml () method, which does not have curly braces, and if there is no content, it will be an error.
Now the more I think this code is completely unnecessary to use abstract classes, with inheritance are also very chicken, well, there is nothing to say as if ...
In addition, I separate MySQL from the outside, so calling the method is very troublesome
1, first instantiate readarticle
2,mysql query, parameters from Readarticle::getsql ();
3, return the MySQL result resource to Readarticle::fetchresult ($result);
4,readarticle::buildhtml (); return HTML
If it's a list loop output, call 3 and 4 again.
Copy Code code as follows:
Abstract class Postparent
{
protected $querySQL;
Public $fetchResult;
Public $timeAgo; Eg:2 days ago
Abstract protected function buildhtml ();
Public Function GetSQL ()
{
return $this->querysql;
}
Public Function Fetchresult ($result)
{
$this->fetchresult = Mysql_fetch_assoc ($result);
}
Public Function error ()
{}
}
Class Readarticle extends Postparent
{
Public function __construct ($id)
{
$this->querysql =<<<eof
SELECT title, author, text, unixtime from post
WHERE id = $id ORDER by Unixtime DESC;
Eof
}
Public Function buildhtml ()
{
Return <<<eof
<div id= "Post-text" >
<div class= "Post-title-div" >
<a href= "http://foodstory.me/post.php?id={$this->fetchresult[' id '}"
class= "Post-title-a" > {$this->fetchresult[' title '}
</a>
</div>
<div class= "Post-info-div" >
<span class= ' post-info-author ' >{$this->fetchresult[' author ']}</span> at
<time class= ' post-info-time ' >{$this->timeago}</time>
</div>
<div class= "Post-p-div" >
{$this->fetchresult[' text ']}
</div>
</div>
Eof
}
}