WHERE statment

3 posts by 2 authors in: Forums > CMS Builder
Last Post: September 7, 2010   (RSS)

Re: [Illume Magazine] WHERE statment

By Chris - August 3, 2010 - edited: August 3, 2010

Hi Illume Magazine,

I'd do this by first doing a getRecords() call to get the 5 slideshow articles, then another getRecords() call to get the remaining articles but excluding the 5 slideshow articles.

Something like this:

list($recentSlideshowArticles,) = getRecords(array(
'tableName' => 'am_articles',
'where' => "category <> '279' AND approved = 1 AND slideshow = 1",
'limit' => 5,
));

$andDontRepeatSlideshowClause = '';
if ($recentSlideshowArticles) {
$slideshowNumsCsv = join(',', array_pluck($recentSlideshowArticles, 'num'));
$andDontRepeatSlideshowClause = ' AND num NOT IN (' . $slideshowNumsCsv . ')';
}

list($moreArticles,) = getRecords(array(
'tableName' => 'am_articles',
'where' => "category <> '279' AND approved = 1" . $andDontRepeatSlideshowClause,
'limit' => 20,
));


The idea here is that after you get the featured slideshow articles, you can compile a list of their nums, and use that list to avoid getting them a second time. For example, if your featured slideshow articles were 11, 13, 15, 17, and 23, you would generate a WHERE clause like this:

category <> '279' AND approved = 1 AND num NOT IN (11, 13, 15, 17, 23)

I hope this helps! If you have trouble getting this to work, please post the complete PHP source code for your page. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] WHERE statment

Hi Chris,

Thank you! This works out well!