MyBB Community Forums
Problem with creating multipage - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Problem with creating multipage (/thread-220863.html)



Problem with creating multipage - Synx - 11-28-2018

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/tutorials/blob/master/advanced_plugin_development.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.


RE: Problem with creating multipage - Synx - 01-11-2019

Sadly this is still not fixed, anyone know what is wrong?


RE: Problem with creating multipage - Synx - 01-14-2019

I've also tried copying it from the forumdisplay for example, but still not working somehow. Is there anything I am missing?


RE: Problem with creating multipage - Mipher - 01-14-2019

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 />";
}