With different objects you can override *all* the methods and get a completely different presentation of the paginated item... (And example of why that can be beneficial can be found here.)Burrito wrote: what advantage do you gain by having them in different objects rather than properties?
Yet another MYSQL Pagination Class
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
The code that TmVW uses is very similar to mine -- because the ideas went into and came out of the same discussion (code here). 
The thing about pagers is that they decompose pretty quickly into a bunch of classes if you start to refactor them. The ususal things: request processor, calculations, datasource, HTML (or other) output. The current Skeleton code has pager code extended from that discussion that does things like recalc and resume when returning from sub-pages of the list, and database independence, etc. I also end up having the Pager just do the basics and have the View build the links exactly how they are specificed by the design.
The thing about pagers is that they decompose pretty quickly into a bunch of classes if you start to refactor them. The ususal things: request processor, calculations, datasource, HTML (or other) output. The current Skeleton code has pager code extended from that discussion that does things like recalc and resume when returning from sub-pages of the list, and database independence, etc. I also end up having the Pager just do the basics and have the View build the links exactly how they are specificed by the design.
(#10850)
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Yeah, but shouldn't it be:Burrito wrote:I hit the link...and the first thing that caught my eye was the example names you selected...![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Code: Select all
$data = array(
array(‘surname’ => ‘Jameson’, ’forename’ => ‘Jenna’),
array(‘surname’ => ‘Banks’, ’forename’ => ‘Briana’),
array(‘surname’ => ‘Giovanni’, ’forename’ => ‘Aria’),
array(‘surname’ => ‘Rush’, ’forename’ => ‘Daniella’),
array(‘surname’ => ‘Flowers’, ’forename’ => ‘April’)
);hmm...I wouldn't knowjayshields wrote:Yeah, but shouldn't it be:Burrito wrote:I hit the link...and the first thing that caught my eye was the example names you selected...![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Code: Select all
$data = array( array(‘surname’ => ‘Jameson’, ’forename’ => ‘Jenna’), array(‘surname’ => ‘Banks’, ’forename’ => ‘Briana’), array(‘surname’ => ‘Giovanni’, ’forename’ => ‘Aria’), array(‘surname’ => ‘Rush’, ’forename’ => ‘Daniella’), array(‘surname’ => ‘Flowers’, ’forename’ => ‘April’) );
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
It was me... i thought this was the code snipets forum and i made that comment. When i saw it was the code critique i thoght my comment was not complete enough to keep and deleted it... i guess i should have kept it.JayBird wrote:Hmmm...weird, I'm sure someone posted a reply when i checked this morning.
Anyway...he was saying that it may be better to just COUNT() the rows in the DB instead of returning the entire resultset. Well, this is something i was talking to JCart about last night.
To do this, we were think of doing something along the lines of (as suggested by Aborint in a thread a while ago)
Anyway... cpliting the query using the front as a separator to explode() should do it... i come in 5 minutes
hey there.. here i am again...
i made some chages but i didnt test them yet.
I replaced this:
By this:
this wont work with subqueries as they have more than one ocorrence of "from".
Also, a dummy doubt i never got solved... when should i use the %delimiters% on str_replace??? and why?
i made some chages but i didnt test them yet.
I replaced this:
Code: Select all
function totalResults()
{
$this->result = mysql_query($this->query);
$this->totalResults = mysql_num_rows($this->result);
if($this->totalResults != 0)
{
$this->maxPage = ceil(($this->totalResults / $this->perPage));
}
}Code: Select all
function totalResults()
{
$this->query = str_replace ( "from", "FROM", $this->query );
$this->query_pieces=explode("FROM");
$this->query_test = "select count(*) from ".$this->query_pieces[1];
$this->result = mysql_query($this->query_test);
$this->totalResults = mysql_result($this->result,0);
if($this->totalResults != 0)
{
$this->maxPage = ceil(($this->totalResults / $this->perPage));
}
}Also, a dummy doubt i never got solved... when should i use the %delimiters% on str_replace??? and why?