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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.