Page 1 of 1

Limit results by range

Posted: Tue Mar 18, 2014 1:35 pm
by midnites
Ok, I'm a PHP newbie and I have a snippet of code that works to limit results to a set category, I need to change that so it limits the results to a range of categories:

Right now it only returns items in Cat number 2, I need it to return items from 2,3,4,5,6,7 - nothing I'm trying is working...

$currentItem = K2Table::getInstance('K2Item', 'Table');
$currentItem->load($itemID);
$itemCat = $currentItem->get('catid');
$includeCat = 2;
if($includeCat)
$query .= " AND c.id = {$includeCat} ";

thanks!

Re: Limit results by range

Posted: Tue Mar 18, 2014 1:45 pm
by Celauran

Code: Select all

$includeCat = array(2, 3, 4, 5, 6, 7);
if ($includeCat) {
    $query .= " AND c.id IN (" . implode(',', $includeCat) . ")";
}

Re: Limit results by range [Solved]

Posted: Tue Mar 18, 2014 2:58 pm
by midnites
Thank you!!!! I was missing the implode part ;-)

Re: Limit results by range

Posted: Wed Mar 19, 2014 1:50 am
by phdiva
Thank you Celauran, I needed that too.