nvsdesign Posted September 8, 2014 Share Posted September 8, 2014 I'm having some problems with a piece of software I use on a clients website. There is a "related items" function module available, with this module you can filter to show items from the same category OR in the same city. But now my client want's the module to show only items that are located in the same category AND the same city. My PHP knowledge is just not good enough to solve this myself, that's why I ask for advice here. I already defined the lines of code that manage the filter, but I don't know how to make this from an "OR" filter to an "AND" filter. Can someone help me with this? // Join over prop mid table if getting related by category if($search_cat) { $cats = ipropertyHTML::getAvailableCats($property->id); if($cats) { $searchwhere[] = 'pm.cat_id IN ('.implode(',', $cats).')'; } } // Filter by city. if($property->city && $search_city) $searchwhere[] = 'p.city = '.$db->Quote($property->city); if( count($searchwhere)) $query->where('('.implode(' OR ', $searchwhere).')'); I have attached the complete file in case that gives a better insight in the filter function. Best regards, Niels helper.php Quote Link to comment https://forums.phpfreaks.com/topic/290916-combined-filter-in-php/ Share on other sites More sharing options...
Ch0cu3r Posted September 8, 2014 Share Posted September 8, 2014 Not sure try changing ' OR ' on this line to ' AND ' if( count($searchwhere)) $query->where('('.implode(' OR ', $searchwhere).')'); Quote Link to comment https://forums.phpfreaks.com/topic/290916-combined-filter-in-php/#findComment-1490296 Share on other sites More sharing options...
Richard_Grant Posted September 8, 2014 Share Posted September 8, 2014 I have absolutely no clue what your using but it looks like some trashy 3rd party php libraries are being used.. it looks like the problem is this line: $searchwhere[] = 'pm.cat_id IN ('.implode(',', $cats).')'; looks like your searching the database (or what ever) for the $cats string. you need to append to that array for the other values you want to search and in the mysql query (you should really be using mysqli pdo) you just change OR to and. Quote Link to comment https://forums.phpfreaks.com/topic/290916-combined-filter-in-php/#findComment-1490297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.