As a testing point, I'm experimenting with my site's article features.
At the moment, the current page queries the database for the latest 20 articles, then using a variety of messy conditional loops and if statements, it sorts them (in ways I can't do through SQL) - for example, it picks 1 article that has a photo and is in a particular section, and puts that at the top in a large box. It then displays all the articles with photos below that, and then below those, all the articles without photos. It's a mess.
In my test so far, I've made a basic Article class and experimented by making an array of those articles, which is how I envision it working when the results come back from the database.
I've tried running code like this:
Code: Select all
$all_articles = array();
$all_articles[] = new Article('123', 'test headline', 'photo.jpg'); // etc
foreach($all_articles as $article) {
if($article->getFilename() != "") { echo "article has a photo<br />"; }
}
Code: Select all
// psuedocode
$articles_with_photos = $articles->getArticlesWithPhotos();
$articles_with_photos->printLargeBox();
Thanks
Matt