Using OR rather than AND with GetList in POG

The POG (Php Object Generator) GetList method supports the setting of multiple conditions out of the box. Heres how to use OR for your conditions, instead of AND.

This is going to be a quick one – something I ran into whilst making this website. There’s mention of it in the POG google group, though not a lot, and only brief explanations for those new to PHP to work with! So here it is.

The following code gets all pets whose breed is ‘dog’, and whose age is under 5:

$pet = new petStore();
$petList = $pet->GetList(array(array("breed", "=", "dog"), array("age", ">", 3)));

What if you wanted all pets whose breed is ‘dog’, OR any pet whose age is under 5? You would write this instead:

$pet = new petStore();
$petList = array_merge($pet->GetList(array(array("breed", "=", "dog"))), ($pet->GetList(array(array("age", ">", 3)))) ;

And there we have it – the trick is ‘array_merge’. I’m hoping this may have saved you a little time!

Update!

To clarify... I've rebuilt since then, this is no longer php. The Django framework now powers Assorted Scribbles.

Written by Tom Bates