News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tiffany Brown's Blog:
Simple pagination for arrays with PHP 5
December 15, 2008 @ 08:48:20

Tiffany Brown has a quick tutorial on a pagination method she's come up with for splitting out array contents over multiple pages.

While working on a recent project, I had to build a feature that displayed a list of files available in a directory. A simple way is just to use scandir() and a foreach loop to spit out a pretty list. There's a small problem though: long lists aren't all that user friendly. I decided instead to paginate the results. Here's one way to do it using PHP 5.

Her method reads in all of the (valid) files from the directory, assigns them to an array and uses the array_chunk function to split them up into groups on five. These groups can be easily looped through and displayed out as links easily.

0 comments voice your opinion now!
pagination php5 arraychunk directory files


blog comments powered by Disqus

Similar Posts

Gergely Hodicska's Blog: What's new in PHP 5.3 - part 1: namespaces

HowToForge.com: How To Set Up suPHP With PHP4 And PHP5

DevShed: User-defined interfaces in PHP 5 - Implementing (X)HTML Widgets

Geeks Not Nerds Blog: Rolling your own Blog Backend from Scratch Part 1

Lars Strojny's Blog: New magic constant in PHP 5.3


Community Events





Don't see your event here?
Let us know!


security podcast introduction voicesoftheelephpant framework list artisanfiles series release laravel tool language opinion library community symfony interview composer version conference

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework