There are two ways to paginate data in Hotaru.
Method 1: Only get the data you need for each page
Method 2: Get all the data first, then divide it into pages
The first is more memory efficient and should be used in most cases. Only use the second for small sets of data.
Here are examples for getting comments.
// get the total number of records $count_sql = "SELECT count(*) AS number FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s"; $count = $h->db->get_var($h->db->prepare($count_sql, 'N')); // get the prepared SQL query $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_archived = %s"; $query = $h->db->prepare($sql, 'N'); // N = No (not archived) // number of items per page $items_per_page = 10; // name of database table to check for updates (cache refreshes when table is updated) $cache_table = 'comments'; // get results for this page $pagedResults = $h->pagination($query, $count, $items_per_page, $cache_table);
Then loop through each item:
if ($pagedResults->items) { foreach ($pagedResults->items as $comment) { // do stuff with this row of data } }
Finally, display the page links at the bottom:
echo $h->pageBar($pagedResults);
// get the data set $sql = "SELECT * FROM " . TABLE_COMMENTS . " WHERE comment_post_id = %d"; $comments = %h->db->get_results($h->db->prepare($sql, $post_id)); // number of items per page $items_per_page = 10; // get items for this page $pagedResults = $h->paginationFull($comments, $items_per_page);
Then loop through each item:
if ($pagedResults->items) { foreach ($pagedResults->items as $comment) { // do stuff with this row of data } }
Finally, display the page links at the bottom:
echo $h->pageBar($pagedResults);