WHERE statment

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

Hi,

I currently have an article site with a slideshow on the homepage: www.illumemag.com.

The slideshow currently lists the 5 most recent articles that are checked to appear in the slideshow. The same articles repeat at the bottom. How can I set it up so if the articles show up on the slideshow, they do not show at the bottom.

The code I have is this:
list($featureRecords) = getRecords(array(
'tableName' => 'am_articles',
'where' => "category <> '279' AND approved = 1",
'limit' => 20
));


If I added AND slideshow=1, the it completely takes out all those articles from the bottom display. I just the 5 most recent articles checked for slideshow not to appear at the bottom.

Thanks.

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