Jump to content

Problems with the OR selector


yesjoar
 Share

Recommended Posts

Hey there,

a little question.

I have three fields for the template project: customer, service, business.

Now I go to a project and want to show more projects on the given value.

So I want to say: Give me all projects, which have customer=$page->customer or service=$page->service or business=$page->business.

The comma is the AND selector. But is there a possibility to set an OR selector between more fields?

Thanks for your input!

Kai.

Link to comment
Share on other sites

Something like this should work...

redacted due to non-functionality and a wish not to confuse those looking for working code

Untested but should work.

There may be quicker/easier way(s). There often are. Anyone?

Edited by DaveP
  • Like 1
Link to comment
Share on other sites

Seems there is a problem with the array merging.

The variables $customer_merched, $service_merched and $business_merched alone, but after the merching the result is empty…

Any other suggestions?

Thanks DaveP!

Link to comment
Share on other sites

$pages->find(..) returns PageArray, not regular array, hence the issue with array_merge(). Also there's no need for array_unique() (should it work), PW handles this already by grouping results by page ID's.

Apart from that, I believe that DaveP is right; you'll have to do separate queries and merge results:

$ps = $pages->find("customer=$page->customer");
$ps->add($pages->find("service=$page->service"));
$ps->add($pages->find("business=$page->business"));

// etc.

One problem with this approach is that, depending on your situation, you might not be able to use limits and built-in pager functions to full extent. Anyway, hope this helps a bit.

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