I have the following class, and I am having the following problem... If I use the findTotalPages() before the setPageLimits(), the new limits set by the setPageLimits() method are not set, but, rather, the limits stay at 0 and 10000 as set by the findTotalPages().
How can I re-set the limits anytime I want with the setPageLimits() or setLimits() methods?
Thanks in advance!
class Gallery {
public function setNumberDisplayed($numberDisplayed) {
$this->numberDisplayed = $numberDisplayed;
}
public function setPageLimits() {
$this->startingEntry = ($this->page - 1) * $this->numberDisplayed;
$this->endingEntry = $this->numberDisplayed;
$this->setLimits($this->startingEntry, $this->endingEntry);
}
/* Sets limits for prepared statement. If limits are not manually set, then
* extreme default values are used.
*/
public function setLimits($skip, $numberRows) {
$this->skip = $skip;
$this->numberRows = $numberRows;
}
public function findTotalPages() {
//Sets exceedingly wide limits for query
$this->setLimits(0, 10000);
//Calculates and sets total number of pages
$this->totalPages = ceil(count($this->findAlbums()) / $this->numberDisplayed);
//Returns total number of pages
return $this->totalPages;
}
public function findAlbums() {
/* Queries database and creates a two dimensional array of all albums
* and each album's associated data.
*/
$query = 'SELECT id, full_title, short_title, dir, timestamp
FROM albums ORDER BY timestamp DESC
LIMIT ?, ?';
$statement = $this->connection->prepare($query);
$statement->bind_param('ii', $this->skip, $this->numberRows);
$statement->bind_result($id, $fullTitle, $shortTitle, $dir, $timestamp);
$statement->execute();
while($statement->fetch()) {
$this->albumData[$dir] = array(
'id' => $id,
'fullTitle' => $fullTitle,
'shortTitle' => $shortTitle,
'dir' => $dir,
'timestamp' => $timestamp
);
}
/* If a dirctory name has been provided via a GET variable, then only
* the album corresponding to that directory name will be returned in the
* array.
*/
if(isset($this->dir)) {
$this->findAlbum();
return $this->albumData;
} else {
return $this->albumData;
}
}
}