MyBB Community Forums

Full Version: Problem with creating multipage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I'm trying to create a pagination using the multipage function, but I have a bit of troubles.
$query = $db->simple_select('logs', 'COUNT(lid) as total');
$total = $db->fetch_field($query, "total");
 
$perpage = 10;

 $pages = ceil($total / $perpage);
 
 if($mybb->input['page']) {
  $page = (int)$mybb->get_input('page', 1);
 }
 else {
  $page = 1;
 }
 
 if($page < 1) {
  $page = 1;
 }
 if($page > $pages) {
  $page = $pages;
 }
 
 $url = $mybb->settings['bburl'] . "/logs.php";
 
 $pagination = multipage($total, $perpage, $page, $url);

I currently have the above and I have followed this tutorial: https://github.com/dragonexpert/tutorial...pment.html

The pagination shows up with all the correct numbers but it seems to display more than 10 per page and when you navigate, it won't seem to navigate to the other page but stays at the same page, even though the param is e.x ?page=2.
Sadly this is still not fixed, anyone know what is wrong?
I've also tried copying it from the forumdisplay for example, but still not working somehow. Is there anything I am missing?
That's a basic pagination that I fetch from memberlist, worked for me.
Create an adminlogs.php file and check it out.

<?php
define("IN_MYBB", 1);
require_once "./global.php";

$url = "{$mybb->settings['bburl']}/adminlogs.php";
$per_page = 10;

$query = $db->simple_select('adminlog', 'COUNT(*) AS adminlogs');
$num_adminlogs = $db->fetch_field($query, "adminlogs");

$page = $mybb->get_input('page', MyBB::INPUT_INT);
if($page && $page > 0)
{
	$start = ($page - 1) * $per_page;
	$pages = ceil($num_adminlogs / $per_page);
	if($page > $pages)
	{
		$start = 0;
		$page = 1;
	}
}
else
{
	$start = 0;
	$page = 1;
}

$multipage = multipage($num_adminlogs, $per_page, $page, $url);

echo $multipage;

$query = $db->simple_select('adminlog', 'uid, module, action', '', array('limit' => "{$start}, {$per_page}"));
while($result = $db->fetch_array($query))
{
	echo "{$result['uid']}, {$result['module']}, {$result['action']}<br />";
}