php - ZF2 Pagination does not work with Union -


i using php zend framework 2.3.3. used paginator select union. code this:

        $where = new where();         $where->like('value', "%$infotosearch%");         $select = new select();         $select->columns(array(new expression('distinct(id)')));         $select->from('products');         $select->where($where);          $select2 = new select();         $select2->columns(array(new expression('distinct(id)')));         $select2->from('products_archive');         $select2->where($where);          $select->combine($select2);          $paginatoradapter = new dbselect($select, $this->getadapter());         $paginator = new paginator($paginatoradapter);          $paginator->setcurrentpagenumber(1);         $paginator->setitemcountperpage(10);          foreach($paginator $product){                 var_dump($product);         } 

then wrong number of products. checked mysql query log , saw query:

( select distinct(id) expression1 `products` `value` '%3%' limit 10 offset 0 ) union ( select distinct(id) expression1 `products_archive` `value` '%3%' ) 

as can see limit 10 offset 0 in wrong place. should @ end of query. bug or there way solve problem?

this occuring because select passed pagination adapter first part of union, limit clause applied part. in order allow limit clause applied result of union, fresh sql\select instance required, similar issue addressed ralph schindler https://github.com/zendframework/zf2/issues/5162#issuecomment-36294281.

in order fix this, need pass new select object :

$union = (new \zend\db\sql\select)->from(['sub' => $select]); $paginatoradapter = new dbselect($union, $this->getadapter()); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -