[nycphp-talk] Problem with Pagination
Joe Crawford Jr.
jcrawford at codebowl.com
Thu Jun 3 16:24:35 EDT 2004
Phillip,
was that the problem?
Joe Crawford Jr.
----- Original Message -----
From: "Phillip Powell" <phillip.powell at adnet-sys.com>
To: "NYPHP Talk" <talk at lists.nyphp.org>
Sent: Thursday, June 03, 2004 4:25 PM
Subject: Re: [nycphp-talk] Problem with Pagination
> Joe Crawford Jr. wrote:
>
> > Phillip,
> >
> > here is your code, the red ( ) are the one's i added ;) let me know if
> > that worked.
> >
> > // NEXT LINK
> > $offset = (int)(@sizeof($this->result) - ($displayItemLimit *
> > ($page - 1)));
> >
> > if ($offset > 0) {
> > $pageNext = $page + 1;
> > $html .= " <b>|</b> <a
> > href=\"index.php?$qs&page=$pageNext\">Next ";
> >
> > $html .= (*(*$offset + (int)$displayItemLimit*)* >
> > @sizeof($this->result)) ? (int)($displayItemLimit - $offset) :
> > $displayItemLimit;
> >
> > $html .= " ${section}s in \"$album\"</a>";
> > }
>
>
>
> Ok, at long long last, after 2 whole days I successfully implemented
> Pagination on at least one of the Views. One down, 12 more to go :(
>
> here is the Pagination method displayPage() in its entirety. Thanx for
> your help, I'm not that quick on complex mathematical algorithms..
>
> [PHP]
> /**
> * Display pagination links
> *
> * @access public
> * @param boolean $willHideAlbum (default false)
> * @return mixed HTML
> */
> function &displayPage($willHideAlbum = false) {
> // STATIC HTML STRING METHOD
> global $section, $action, $album, $headerMenuArray,
> $willPaginate, $displayItemLimit;
> foreach ($_REQUEST as $key => $val) if (!isset(${$key})) ${$key}
> = $val;
>
> $qs =
> "section=$section&action=$action&sort=$sort&chooseAlbum=1&album=" .
> urlencode($album) . '&willKeepPageSession=1'; // FOR EASE OF WRITE
>
> if ((int)$page === 0) $page = 1;
> $page = (int)$page; // CONVERT TO INTEGER
>
> if (@sizeof($this->result) > $displayItemLimit &&
> $willPaginate) {
>
> $html .= "<div align=\"center\">\n";
>
> // PREVIOUS LINK
> if ((int)$page !== 1) {
> $pagePrev = $page - 1;
> $html .= " <a href=\"index.php?$qs&page=$pagePrev\">Previous
> $displayItemLimit ${section}s";
> if (!$willHideAlbum) $html .= " in \"$album\"";
> $html .= '</a> <b>|</b> ';
> }
>
> $numPages = (int)(@sizeof($this->result) /
$displayItemLimit);
>
> // ALL PAGES (PAGE NUMBER) LINK(S) EXCEPT FOR LAST PAGE
> for ($i = 1; $i <= $numPages; $i++) {
> if ((int)$i === (int)$page) $html .= "$i "; else $html .=
> "<a href=\"index.php?$qs&page=$i\">$i</a> ";
> if ($i + 1 <= $numPages) $html .= '<b>|</b> ';
> }
>
> // LAST PAGE NUMBER LINK
> if (@sizeof($this->result) % $displayItemLimit != 0) {
> $html .= '<b>|</b> ';
> if ((int)$i === (int)$page) $html .= "$i "; else $html
> .= "<a href=\"index.php?$qs&page=$i\">$i</a> ";
> }
>
> // NEXT LINK
> $pageItemCount = (int)(@sizeof($this->result) - ($page *
> $displayItemLimit));
> if ($page <= $numPages && (int)$pageItemCount > 0) {
> $pageNext = $page + 1;
> $html .= "<b>|</b> <a
> href=\"index.php?$qs&page=$pageNext\">Next ";
> $html .= ($pageItemCount < $displayItemLimit) ? $pageItemCount
> : $displayItemLimit;
> $html .= " ${section}s";
> if (!$willHideAlbum) $html .= " in \"$album\"";
> $html .= '</a>';
> }
>
> $html .= "\n</div>\n";
> }
> return $html;
> }
> [/PHP]
> Phil
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
>
>
More information about the talk
mailing list