Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-06-2008, 02:47 PM
carras's Avatar
Junior Member
 
Join Date: Jul 2008
Posts: 1
Question Zend_Db_Select Brackets

Hi

I have problem with Zend_Db_Select.

if i want do SQL like this:

Code:
SELECT DISTINCT `items`. * , `users`.`active` AS `useractive`
FROM `items`
LEFT JOIN `tagToItem` ON tagToItem.iid = items.id
LEFT JOIN `tags` ON tagToItem.tid = tags.id
WHERE (items.status =10)
AND 
((items.name LIKE '%for%')OR (tags.name LIKE '%for%')OR (items.desc LIKE %for%'))
i must add this extra bracket before 'AND' like this:
PHP Code:
$items->select()
 ->
distinct()
 ->
from(array('items' => 'items'))
 ->
where('items.status=?',CU_Enum_ItemStatus::ACTIVE)
 ->
setIntegrityCheck(false)
 ->
where('(items.name LIKE ?','%'.$word.'%')               //here bracket before
 
->joinLeft('tagToItem','tagToItem.iid=items.id',array())
 ->
joinLeft('tags','tagToItem.tid = tags.id',array())
 ->
orWhere('tags.name LIKE ?','%'.$word.'%')
 ->
orWhere('items.desc LIKE ?)','%'.$word.'%')             //here bracket after 

but i don't like this solution

did anyone have nice method to do bracets in SQL using Zend_Db_Select?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-15-2008, 08:09 PM
Junior Member
 
Join Date: Jul 2008
Posts: 5
Default

An example from the manual:
PHP Code:
$select $db->select()
    ->
from('products',
        array(
'product_id''product_name''price'))
    ->
where("price < $minimumPrice OR price > $maximumPrice")
    ->
where('product_name = ?'$prod); 
I use it too but I do not like it very much.
And you'd better use this solution too because yours is very confusing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:58 AM.