Feb 1 2008

Symfony (Propel) Pagination on Multiple Tables

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.

Propel multiple 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;$igetResults() ) > 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.

1 Comments on this post

Trackbacks

  1. Ganesh said:

    Hello Sajit,

    I am symfony programer, i have use symfony, but when i propel pagination for showing database records page by page. i found that suppose i want to show 10 records out 50 records at that time pager fetch all 50 records and show only 10 records.
    This makes page to take more time when it loads.Actually it has to fetch only 10 records and to show them.

    Do you have solution for this.
    any suggestion from you will help me.

    September 22nd, 2008 at 12:37 pm

LEAVE A COMMENT

Subscribe Form

Subscribe to Blog

Sponsors

    Advt on sajithmr.com
    Advt on sajithmr.com
    Itslife Online
    Advt on sajithmr.com

Recent Comments

  • Binny V A: Thanks for the post - love the picture ;-)
  • TheAnand: A lot of people are seeing errors with google video chat….is there any other software which has to be...
  • Alex: Wow, interresting analysis you have done! I’m trying to run GoogleVoiceAndVideoSetup on linux, using...
  • Mella Fitriansyah: Nice plugin, I will try to add this plugin in my blog…
  • Mella Fitriansyah: Nice Info, Sir i will reading your another post success for you

Recent Readers

JOIN MY COMMUNITY!

Recent Posts