V
V
Vadim2014-08-05 18:52:02
Zend Framework
Vadim, 2014-08-05 18:52:02

How to make a paginator from 2 sql queries, zend_paginator?

Hello. I have a table with data, I need to make a paginator for these records.
There are 2 queries:
type=1 ORDER BY priority DESC
type=2 ORDER BY time
At the beginning on the first pages of the paginator, there should be entries with type 1, and sorted by priority. And when they run out, those records whose type is equal to 2 are displayed, and they are sorted by the time column.
I tried to do it like this:

$select1 = $this->_dbTable
                        ->select()
                        ->where('`type` = 1')
                        ->order('priority DESC');
        $select2 = $this->_dbTable
                        ->select()
                        ->where('`type` = 2')
                        ->order('time');
      $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect(
        $this->_dbTable->select()->union(array($select1,$select2))
        ));
      $paginator->setCurrentPageNumber($pageNumber);
      $paginator->setItemCountPerPage($perPage);
      $paginator->setPageRange(1);

I am getting an error:
Incorrect usage of UNION and ORDER BY

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