views:

337

answers:

1

Can anyone help me to do this in the right way?I mean.. like that : $db->select()->group..... I tried a few times, but doesn't work for me :(

$this->q->fetchAll('select * from clubs, club_photos_default where clubs.id=club_photos_default.c_id group by clubs.id');

Best Regards,

+5  A: 

The right way in this case is the way you're doing it, since the whole SQL query is known and static.

You are not required to use Zend_Db_Select to build queries procedurally. In fact, it's often more complex and less readable than just typing out the literal SQL query.

Use Zend_Db_Select when you need to build a query procedurally, based on variables and logic in your application code.

But to answer your question, this should work:

$select = $db->select()
  ->from(array('c'=>'clubs'))
  ->join(array('p'=>'club_photos_default'), 'c.id=p.c_id')
  ->group('c.id');
$this->q->fetchAll($select);

(Assuming $db is an object of Zend_Db_Adapter.)

Bill Karwin