Tags for pagination

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Tags for pagination

Post by calguy1000 »

Hi Wishy

What tags should I use for the pagination markers (prev, next, total pages, etc).... couldn't find anything well marked in the style.css in the admin directory.

sorry, no IRC access at the office
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Shannon

Tags for pagination

Post by Shannon »

new install of 7.3 and a fresh database... In the admin section on most links I get Fatal error: Call to undefined function: pagination() in /home/*****/public_html/admin/listgroups.php on line 33 ???

Any ideas anyone? I am stumped...

:?: Thank you,
Shannon
100rk

Solution for pagination

Post by 100rk »

I changed implemetation of function pagination(..) in file 'page.functions.php' from

Code: Select all

/**
 * Creates a string containing links to all the pages. 
 * @param page - the current page to display
 * @param totalrows - the amount of items being listed
 * @param limit - the amount of items to list per page
 * @return a string containing links to all the pages (ex. next 1,2 prev)
 */
 function pagination($page, $totalrows, $limit)
 {
	$page_string = "";
	$from = ($page * $limit) - $limit;
	$numofpages = $totalrows / $limit;
	if ($numofpages > 1)
	{
		if($page != 1)
		{
			$pageprev = $page-1;
			$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$pageprev\">".lang('previous')."</a> ";
		}
		else
		{
			$page_string .= lang('previous')." ";
		}
		for($i = 1; $i <= $numofpages; $i++)
		{
			if($i == $page)
			{
				$page_string .= $i." ";
			}
			else
			{
				$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
			}
		}

		if(($totalrows % $limit) != 0)
		{
			if($i == $page)
			{
				$page_string .= $i." ";
			}
			else
			{
				$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
			}
		}

		if(($totalrows - ($limit * $page)) > 0)
		{
			$pagenext = $page+1;
			$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=$pagenext\">".lang('next')."</a>";
		}
		else
		{
			$page_string .= lang('next')." ";
		}
	}
	return $page_string;
 }
to

Code: Select all

/**
 * Creates a string containing links to all the pages. 
 * @param page - the current page to display
 * @param totalrows - the amount of items being listed
 * @param limit - the amount of items to list per page
 * @param params - additional params for href - array of strings
 * @return a string containing links to all the pages (ex. next 1,2 prev)
 */
 function pagination($page, $totalrows, $limit, $params="")
 {
 	$added_params = "";
	if (is_array($params)) {
		foreach ($params as $param) {
			$added_params .= "&".$param;
		}
	}
	
	$page_string = "";
	$from = ($page * $limit) - $limit;
	$numofpages = $totalrows / $limit;
	if ($numofpages > 1)
	{
		if($page != 1)
		{
			$pageprev = $page-1;
			$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$pageprev.$added_params."\">".lang('previous')."</a> ";
		}
		else
		{
			$page_string .= lang('previous')." ";
		}
		for($i = 1; $i <= $numofpages; $i++)
		{
			if($i == $page)
			{
				$page_string .= $i." ";
			}
			else
			{
				$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i.$added_params."\">$i</a> ";
			}
		}

		if(($totalrows % $limit) != 0)
		{
			if($i == $page)
			{
				$page_string .= $i." ";
			}
			else
			{
				$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i.$added_params."\">$i</a> ";
			}
		}

		if(($totalrows - ($limit * $page)) > 0)
		{
			$pagenext = $page+1;
			$page_string .= "<a href=\"".$_SERVER['PHP_SELF']."?page=".$pagenext.$added_params."\">".lang('next')."</a>";
		}
		else
		{
			$page_string .= lang('next')." ";
		}
	}
	return $page_string;
 }
So, I can use this function like at file 'admin/adminlog.php', but (for example) with last parameter array('module=XY').

Caution for newbies: character '&' is added automatically.
100rk

Post scriptum

Post by 100rk »

Of course, I speak ONLY about pagination in admin interface - if You want use this solution for pagination at Your webpages, You have to change parameter $config["query_var"] in file 'config.php' to another one
8)
mo

Re: Tags for pagination

Post by mo »

hi,

how can i do this for pagination at my web pages then? i duno about php much. if you can help me w/example. i appreciate it.

thanks,
mo
100rk

Re: Tags for pagination

Post by 100rk »

mo wrote: how can i do this for pagination at my web pages then?
I think every PHP developer have his own way - whole problem is only about SQL statement SELECT and its part LIMIT. In case function 'pagination()' You are limited by it's parameter 'page', so if You have default install of CMSMS (no mod_rewrite, no changes in page variable), You can not use it in public interface.

I am using class SmartyPaginate in my Smarty-related projects, because this class is able to do almost all pagination-work for You (Your choice of pagination variable, possibility of more then one pagination bar at one page etc). For documentation, examples, demo and download see http://www.phpinsider.com/php/code/SmartyPaginate/.

Of course, if You do not like SmartyPaginate output for pagination, there is plenty of smarty variables of this class for creation Your own pagination bar - just read whole documentation of this class. IMHO it is very usable.
Last edited by 100rk on Mon Aug 08, 2005 9:51 am, edited 1 time in total.
mo

Re: Tags for pagination

Post by mo »

thank you.

oh man, this is too difficult for me—i'm just a designer and know basic html/css. i'm just trying to do my portfolio website w/CMS. which i have very little knowledge about. and all i wanna do is to make the News pages w/paging. too bad, i'm not a program developer:(
100rk

Re: Tags for pagination

Post by 100rk »

mo wrote: all i wanna do is to make the News pages w/paging
I am not pretty sure, what it means ;-) - but You can organize Your News items into categories, every category can become on other page and You can define how much items (of news in this category) You want to display - example from Help of New module: {cms_module module="news" number="5" category="beer"}

And if You will combine this simple trick with user contributed plugin 'Improved version of cms_selflink' (download here: http://wiki.cmsmadesimple.org/tiki-inde ... ed+Plugins, forum topic here:http://forum.cmsmadesimple.org/index.ph ... 112.0.html), You will propably obtain almost all what You want - this plugin allows automatically create links 'previous page' and 'next page'.
Last edited by 100rk on Mon Aug 08, 2005 11:23 am, edited 1 time in total.
Post Reply

Return to “Developers Discussion”