/ Published in: PHP
There are plenty of classes out there to paginate through database results, well, here's one to paginate through a static array of items. Written quite a few years ago, recently recovered from a crashed drive.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Paginate_Array { var $_array; var $_per_page; var $_lpage; var $_offset; function Paginate_Array($array, $offset = 0, $per_page = 3) { $this->_array = $array; $this->_per_page = $per_page; $this->_offset = $offset; } function getOffset() { } function getPages() { for ($i=0; $i <= ($this->_lpage - 1); $i++) { $this->_out[$i+1] = $i * $this->_per_page; } return $this->_out; } function _getLastOffset() { $_arr = $this->_out; } function hasPrev($text) { return ($this->_offset > 0) ? $text : ''; } function hasNext($text) { return ($this->_offset < self::_getLastOffset()) ? $text : ''; } } // end class ?>