Re: how to use Pager on an sql (Page pagination)

From: Date: Mon, 12 Jul 2004 15:27:04 +0000
Subject: Re: how to use Pager on an sql (Page pagination)
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13661@lists.php.net to get a copy of this message
On Mon, 12 Jul 2004 23:02:28 +0800, Louie Miranda wrote: > Thanks Lorenzo, > > I'll try to figure out first how to get the sql query out from the > pager. Im just starting to learn PEAR, and so far. I like it, but > its quite hard for me as of now. > > I'll post here tom, what will be the details of my research for the > Pager. > > Hope i could get it to work. a quick, easy, usage example: ================================== $query = 'SELECT * FROM mytable'; $myRows = $db->getAll($query); $params = array( 'mode' => 'Sliding', 'perPage' => 10, 'delta' => 2, 'itemData' => $myrows, ); $pager = & Pager::factory($params); $mydata = $pager->getPageData(); foreach ($mydata as $row) { //do sth } ================================== If you have a BIG table, with LOTS of records, then the above approach may not be the most performant one, because it retrieves all the records, and then extracts the wanted ones from the results array. Here's a valid alternative, using the wrapper [1] I already suggested in my other mail, which only fetches the records you really need in your page: ================================== $query = 'SELECT * FROM mytable'; $params = array( 'mode' => 'Sliding', 'perPage' => 10, 'delta' => 2, ); $page = Pager_Wrapper_DB($db, $query, $params); foreach ($page['data'] as $row) { //do sth } ================================== BTW: the manual [2] is your friend, there are other usage examples there ;-) HTH Regards, -- Lorenzo Alberton http://pear.php.net/user/quipo [1] http://seagull.phpkitchen.com/docs/wakka.php?wakka=PagingRecordsets [2] http://pear.php.net/manual/en/package.html.pager.php

« previous php.pear.general (#13661) next »