I have been looking around recently for a decent paging class to work with mysqli and mysqli stmt.
Currently I have a method such as:
public function getAll()
{
if ($stmt = $this->db->prepare("SELECT `id`, `name`, `url`, `order` FROM `categories` ORDER BY `order` ASC"))
{
$stmt->execute();
$stmt->bind_result($this->id, $this->name, $this->url, $this->order);
while ($stmt->fetch())
{
$entry[] = $this->objectToArray();
}
return $entry;
}
errorLog($this->db->error.$stmt->error);
}
$this->objectToArray() just generates an array of the object variables which is pushed through to what is essentially the controller -> view.
I have been thinking what the most effective way of paging my results would be. I could easily do it at array level but it would be a huge waste of resource pulling out 500+ rows then to only use 30 of them. But the bit I am struggling with is how to get the paging data into query level without having to write into each query the paging results.
Ideally I would extend the database class and call the paging object rather than db
if ($stmt = $this->paging->prepare("SELECT id, name, url, order FROM categories ORDER BY order ASC"))
and extend the prepare method to include the paging additions for the query.
Any input would be greatly appreciated
Cheers
J