Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
Created February 26, 2013 23:18
Show Gist options
  • Save ijmorgado/5043284 to your computer and use it in GitHub Desktop.
Save ijmorgado/5043284 to your computer and use it in GitHub Desktop.
This is a small piece of code to create a select statement with 2 like clauses connected by "OR". It was made in ZF2. :)
$adapter = $this->tableGateway->getAdapter();
$select = new Select();
$select->from('alb_imagen')
->columns(array('itemId' => 'id_imagen',
'value' => 'titulo'))
->limit(12)
->join(array('t' => 'alb_thumbnail'),'t.id_imagen = alb_imagen.id_imagen',array('imagen' => 'nombre'))
->where('t.tipo = \'MINI_ICON50X50\' and alb_imagen.activo =1')
->where(array(new PredicateSet(array(new Like('titulo', "%".$query."%"),
new Like('descripcion', "%$query%")
),
PredicateSet::COMBINED_BY_OR
)));
@ijmorgado
Copy link
Author

However...if we just want to do a couple of like predicate with AND clause, just need to do:

...all stuff with select object..//
->where->like('titulo', "%".$query."%")->like('descripcion', "%$query%");

..and that will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment