Jump to content

Simple issue with find based on Select Option value


cst989
 Share

Recommended Posts

Can anyone tell me why I get all results from the selected template on this search, only the max price (price<=999999) changes the number of results returned. Otherwise, all properties are returned despite there being lots of different values

I'm sure its something really simple

$pages->find("template=property,start=0,price>=0, price<=9999999, beds>=1, property_type=2,limit=3,sort=created")

 

Link to comment
Share on other sites

What do you mean? ?

If you only have this:

30 minutes ago, cst989 said:

$pages->find("template=property, start=0, price>=0, beds>=1, property_type=2, limit=3, sort=created")

 

instead of

31 minutes ago, cst989 said:

$pages->find("template=property, start=0, price>=0, price<=9999999, beds>=1, property_type=2, limit=3, sort=created")

 

Then of course you'll get much more results. Omit the limit parameter to really see how many results you'd get. But in any case, it's not logical that you get ALL properties listed (e.g. even property types 1 or 3). Care to explain a bit better?

  • Thanks 1
Link to comment
Share on other sites

Sorry yes, it's not that removing price<=99999.. changes the result, but that nothing changes the result except that

Like you say, I am returning all properties, including type 1, type 3, blank type etc., when it should only be type 2. The limit isn't even working, it's returning all 10 properties.

Link to comment
Share on other sites

Ok so this is a bit odd, I have actually been doing this:

$properties = $pages->find("$filter");

Which is not filtering results properly.

However, if I echo out $filter then manually paste the result into the find instead (so it looks more like my example in the first post), it works...??

If I var_dump $filter, it's just a string... I have tried it with and without quotes

Link to comment
Share on other sites

And that $filter comes from where? From a select option (thread title) value?

You should try to solve this puzzle with Tracy Debugger. See what value exactly is taken from the select option and what is actually passed to find(). Perhaps you need to do something like using unformatted value, or PW is somehow doing sanitation and wipes out some characters. Just wild guesses, but maybe TD will show you what happens, and where.

  • Thanks 1
Link to comment
Share on other sites

I worked it out while putting the code in this post and trying to remove parts til it works.

I had part of my filter like this

if(isset($request)) {
    $filter .=
        'price>=".(int) $request['min'].', 
         price<='.(int) $request['max'].', 
         beds>='.(int) $request['beds'].', 
         property_type='.(int) $request['property_type'];
}

As it turns out, you can't put line breaks in your filter like this! They obviously didn't show up in var_dump or the browser when echoed, so I missed this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...