Jump to content

special character to select all records


manlio
 Share

Recommended Posts

Hi I have simple question that I'm not able to solve on my own :-[  

I retrieve data with find like this

$users->find("template=user,user_region=$inputregion,include=all");

Everything works when $inputregion is a single "region" but I would like to retrieve also all regions but I don't know how to set the correct value of  $inputregion.

I tried with something like

$inputregion = "%" or $inputregion="/%/" with no luck.

Thank you

Link to comment
Share on other sites

So your $inputregion can be multiple regions? If it's an array you can implode it with a pipe symbol:

$inputregion = implode('|', $inputregion); // creates something like 'region1|region2|region3'

So the selector looks something like this:

$users->find("template=user, user_region=region1|region2|region3, include=all");

and it matches users with either of those regions

  • Like 1
Link to comment
Share on other sites

Thank you owzim. I have learnt something more, but my case is a little different (sorry to be not enough clear).

My $inputregion get single data from Url segment.

So I have something like

www.mysite.it/list/region1

www.mysite.it/list/region2

ecc...

I would like to display users of all region using 

www.mysite.it/list/

Thanks

Link to comment
Share on other sites

Why the not list the users without the region selector?

$users->find("template=user, include=all");

Or if you want to display all users that have a region assigned (matching users with a non-empty user_region field):

$users->find("template=user, user_region!='', include=all");
  • Like 1
Link to comment
Share on other sites

Ok I thought about that, but I didn't want to have two find queries for this purpouse and I believed I was missing the "wildcar".

My php skill is really low so forgive me if I'm saying something obviously wrong. I would have to write two different queries like these, am I right?

if (isset ($inputregion)) { 
$users->find("template=user,user_region=$inputregion,include=all");
} else {
$users->find("template=user, user_region!='', include=all");
}

Thanks

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