db = $db; $this->sql = $sql; $this->rows = $rows; $this->limit = $limit; $this->results = $results; $this->uri_tail = ''; $this->uri = $uri; if (strstr($this->uri, '?')) { $this->sep = ini_get('arg_separator.output') . 'start='; } elseif ($this->uri_tail == '' or $this->uri_tail > 0){ $this->sep = ''; } else { $this->sep = '?start='; } $this->buildData(); } function buildData() { $this->start = isset($_GET['start']) ? (int) $_GET['start'] : (int) $this->uri_tail; if ($this->start < 0) { $this->start = 0; } if ($this->start >= $this->rows) { $this->start = $this->rows - $this->limit; } $this->from = $this->start + 1; $this->to = $this->start + $this->limit; if ($this->to > $this->rows) { $this->to = $this->rows; } $this->pages = ceil($this->rows / $this->limit); $this->page = ceil($this->start / $this->limit) + 1; if ($this->page > $this->pages) { $this->page = $this->pages; } $this->prev = $this->start - $this->limit; $this->prev = ($this->prev >= 0) ? $this->prev : null; $this->next = $this->start + $this->limit; $this->next = ($this->next < $this->rows) ? $this->next : null; } function &getResult() { return $this->db->limitQuery($this->sql, $this->start, $this->limit); } function link($param) { if ($param) { return ($this->uri . $this->sep . $param); } return $this->uri; } function getNav() { $html = ''; if (is_int($this->prev)) { $html .= 'Previous'; } else { $html .= 'Previous'; } $html .= ' | '; $radio = floor($this->maxpages / 2); $minpage = $this->page - $radio; if ($minpage < 1) { $minpage = 1; } $maxpage = $this->page + $radio - 1; if ($maxpage > $this->pages) { $maxpage = $this->pages; } foreach (range($minpage, $maxpage) as $i) { $offset = $this->limit * ($i - 1); if ($this->start == $offset) { $html .= " $i "; } else { $html .= ' ' . "$i "; } } $html .= ' | '; if (is_int($this->next)) { $html .= 'Next'; } else { $html .= 'Next'; } return $html; } function getHeader() { return "$this->results $this->from - $this->to of $this->rows. "; } } // end class MultiPage ?>