Jump to content

Combined filter in php


nvsdesign

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/290916-combined-filter-in-php/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.