I'd like to know how to properly write mySQL statement using ZEND in this case:
SELECT * FROM `users` WHERE role_id = 2 AND status = 2 AND bddate BETWEEN '1988-05-07' AND '1991-01-01' ORDER BY lastname DESC
I'll have if statements, for ex. if in the filter user selected role_id I'll include it in WHERE and so on, the same with the rest of them.
So far I have 1 WHERE condition and I have done it like this (now I need more complicated one):
$select = $this->select()
->setIntegrityCheck(false)
->from(array('u'=>'users'))
->join(array('r'=>'user_roles'), 'u.role_id = r.role_id', array('role'=>'title'));
if(count($filters) > 0) {
foreach($filters as $field => $filter) {
$select->where($field . ' = ?', $filter);
}
}
if(null != $sortField) {
$select->order($sortField);
}