Alex (SirShurf) Frenkel's Blog

A web log of a PHP professional

Grouping orWhere elements in Zend Framework Zend_Db_select

leave a comment »

Practicly each time I am working with Zend_Db_Select (with Table or without it) I am searching for how easy to group orWhere elements.

After lot’s of searching and try and error’s I have come to this code:


if (false !== $this->_customSearchKeyword) {

$searchFields = array(‘p.photo_name’, ‘p.photo_desc’);


$keywordWhere = array();


if (!empty($searchFields)) {


foreach ($searchFields as $searchField) {

$searchField = $db0->quoteIdentifier($searchField);
$keywordWhere[] = ‘(‘ . $db0->quoteInto(“$searchField = ?”,

$this->_customSearchKeyword) . ‘)’;

}
$select->where( implode(‘ OR ‘, $keywordWhere) );

}

}

I hope that would be of some help to somebody 🙂 more then me I mean

Advertisement

Written by Alex (Shurf) Frenkel

May 13, 2010 at 7:11 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: