Limit results by range

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
midnites
Forum Newbie
Posts: 2
Joined: Tue Mar 18, 2014 1:31 pm

Limit results by range

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Limit results by range

Post by Celauran »

Code: Select all

$includeCat = array(2, 3, 4, 5, 6, 7);
if ($includeCat) {
    $query .= " AND c.id IN (" . implode(',', $includeCat) . ")";
}
midnites
Forum Newbie
Posts: 2
Joined: Tue Mar 18, 2014 1:31 pm

Re: Limit results by range [Solved]

Post by midnites »

Thank you!!!! I was missing the implode part ;-)
phdiva
Forum Newbie
Posts: 1
Joined: Wed Mar 19, 2014 1:44 am

Re: Limit results by range

Post by phdiva »

Thank you Celauran, I needed that too.
Post Reply