If you are a symfony programmer, just read this. Otherwise you can skip this topic. We all know that one of the useful thing in every website creation is the pagination. Symfony uses propel pagination for showing database records page by page.

But suppose the case of showing records from different table . You cannot use normal pager class of propel to show the results form multiple table. For that purpose you need to get the results as result set and have to create custom pagination by adding setLimit to the criteria.

But when i develop mobshare search page, the requirement is that when a key or pattern is search , the first page needed to contain all the results, means mixed results from photos, videos and users. But the data are stored in three different tables : Photos , Videos and Users.

So i created a turing machine like structure. Its geographical structure is like three tapes aligned in parellel and a head and level tracker read the data from these three tapes simultaneously . These tapes represents each pager. Head is the reader and level indicates which tape is currently reading . These tapes are arrange in small to high manner in the order of number of results of each pager.

Click read more:

See the code i have made:

$ObjectRsArray = array(); $PagerArray = array(); if($this->UserPager->getLastPage() >= $this->getRequestParameter(’page’,1) ) { $ObjectRsArray[] = $this->UserPager->getResults(); $PagerArray[]=$this->UserPager; } if($this->PhotosPager->getLastPage() >= $this->getRequestParameter(’page’,1) ) { $ObjectRsArray[] = $this->PhotosPager->getResults(); $PagerArray[]=$this->PhotosPager; } if($this->VideosPager->getLastPage() >= $this->getRequestParameter(’page’,1) ) { $ObjectRsArray[] = $this->VideosPager->getResults(); $PagerArray[]=$this->VideosPager; } $this->ObjectRsArray = math::SortObjects($ObjectRsArray); $this->MainPager = math::getBigPager( $PagerArray ); //The math lib is as below: count($a[$j]) ) list ($a[$j],$a[$i]) = array($a[$i],$a[$j]); return $a; } public function getBigPager($a) { for($i=0;$i< count($a) ; $j++) if( count($a[$i]->getResults() ) > count($a[$j]->getResults() ) ) list ($a[$j],$a[$i]) = array($a[$i],$a[$j]); return end($a); } } //These all happen in the action area. Now in the template, user normal pagination for the big pager, because big pager contains the maximum pages. //And for showing mixed results use the below code (turing machine implementation ): //Here the record is $ObjectRsArray[$reader][$head]. //You can use this object to show your results. eg: $ObjectRsArray[$reader][$head]->getId() //etc.