I'm building a freelancing site (think scriptlance) which has listings of projects both on the home page and the listings page. I thought it would be a good chance to implement OOP techniques.
I was thinking I would create a project class which among other things would have a function to echo the relevant contents for the home and listing page. I would like some advice on my proposed method.
I would create a class of something like:
class project {
...
public function PrintSmallListing() {
echo "<div id="smallListing">
<h2>Listing Title</h2>
<span>listing description</span>
...
</div>";
}
}
Then on the relevant pages I would execute a database query then loop through the result create an array of these objects based on the data from the query. I would then display the listing of projects by looping through the array of objects and calling the
This means my queries would not be contained within my classes, otherwise I would need to call a separate query for every listing.
So my question is, is this a good way to implement OOP in PHP, are there some followed practices when using OOP for this kind of problem? or how would you personally do it?