B
B
byms2016-04-19 01:06:52
MySQL
byms, 2016-04-19 01:06:52

For joining 4 products in each category?

there is a request

$collections_sql = Yii::app()->db->createCommand()
            ->select('t.id, t.main_image, t.title, t.alias, t.sortOrder')
            ->from('tbl_collection (
                SELECT * as c2 FROM tbl_catalog
            ) as t')
            ->join('tbl_gallery_photo gp', 'gp.gallery_id = t.id');
            if(Yii::app()->request->getParam('model_id')){
                $collections_sql->join('tbl_catalog c', 'c.gallery_photo_id = gp.id AND c.parent_model_id=:model_id',array(':model_id'=>Yii::app()->request->getParam('model_id')));
            }else{
                $collections_sql->join('tbl_catalog c', 'c.gallery_photo_id = gp.id');
            }
            $collections_sql->limit($count, ($page-1)*$count);
            $collections_sql->order('sortOrder ASC');
            $collections = $collections_sql->queryAll();

you need to make the join of the tbl_catalog table grab not all records, but 4 pieces each where c.gallery_photo_id = gp.id how can this be done, or rebuild the query?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question