2008年12月11日星期四

Re: [fw-db] nesting conditions

On Thu, Dec 11, 2008 at 9:22 AM, ViktorG <info@intelligibel.de> wrote:
>
>
> PHPScriptor wrote:
>>
>> How I do it:
>>
>> $model = new tblModel();
>> $select = $model->select();
>> $select->where('(x=1 OR x=2)');
>> $select->where('(y=1 OR y=2)');
>>
>>
>> ViktorG wrote:
>>>
>>> Hi,
>>>
>>> I would like to do something like:
>>>
>>> SELECT * FROM tbl WHERE (x = 1 OR x = 2) AND (y = 1 OR y = 2);
>>>
>>> Is this possible by using the Zend DB Table Object?
>>>
>>
>>
> Thanks for the replies. I already thought that this would be the only way.
> So nesting is not supported. Otherwise I could do something like:
>
> $select->where($select->orWhere('x=?',1)->orWhere('x=?',2));
> $select->where($select->orWhere('y=?',1)->orWhere('y=?',2));
>
> @Till
> No, the keys are not primary ones, the real use case ist more like:
>
> $sSearch = 'Bill Gates'; // user input
>
> $aSearch = explode(' ', $sSearch);
> $oModel = new tblModel();
> $oAdapter = $oModel->getAdapter();
> $oSelect = $oModel->select();
> foreach($aSearch as $sSearchPart){
> $sSearchPart = $oAdapter->quote($sSearchPart);
> $oSelect->where('(forname LIKE ' . $sSearchPart . ' OR surename LIKE ' .
> $sSearchPart . ')');
> }
>
> Thanks

If it's MySQL, make a FULLTEXT across the two columns, and use MATCH()
AGAINST().

Till

没有评论: