How does this pagination script work?

I found this database-free pagination script on another forum the other day; unfortunately, the thread was old, and the author didn’t provide instructions on how to use it. My questions are: 1. What defines an entry, and 2. what defines how many entries one can insert before a second page starts?
Here’s the code:
[php]<?php
class display {
function pagination($rows, $per_page, $current_page, $page_link) {
global $core,$C;

	// Create a Page Listing
	$this->pages = ceil(10 * $rows / $per_page);
	
	// If there's only one page, return now and don't bother
	if($this->pages == 1) {
		return;
	}
	
	// Pagination Prefix
            $output .= "<!-- Pagination by Dennis Pedrie. Used by Permission -->";
	$output = "Pages: ";
	
	// Should we show the FIRST PAGE link?
	if($current_page > 2) {
		$output .= "<a href=\"". $page_link ."?page=1/\" title=\"First Page\">&lt;&lt;</a>";
	}
	
	// Should we show the PREVIOUS PAGE link?
	if($current_page > 1) {
		$previous_page = $current_page - 1;
		$output .= " <a href=\"". $page_link .">page=". $previous_page ."/\" title=\"Previous Page\">&lt;</a>";
	}
	
	// Current Page Number
	$output .= "<strong>[ ". $current_page ." ]</strong>";
	
	// Should we show the NEXT PAGE link?
	if($current_page < $this->pages) {
		$next_page = $current_page + 1;
		$output .= "<a href=\"". $page_link ."?page=". $next_page ."/\" title=\"Next Page\">&gt</a>";
	}
	
	// Should we show the LAST PAGE link?
	if($current_page < $this->pages - 1) {
		$output .= " <a href=\"". $page_link ."?page=". $this->pages ."/\" title=\"Last Page\">&gt;&gt</a>";
	}
	
	// Return the output.
	return $output;
}

}
$display = new display;
echo $display->pagination(“45”, “15”, “1”, “http://theapplenewsreel.com/news/index.php”);
?>[/php]

if your site has a functions page that is a separate file like functions.php. IF so here is an easier:

this is the function:
[php]function countLogs() {
global $dbprefix;

$query = “SELECT COUNT(id) FROM {$dbprefix}logs”;
$result = mysql_query($query)
or die(mysql_error());
$row = mysql_fetch_array($result);
@extract($row);

return $row[0];

}[/php]

here is the php file:
[php]<?php
echo "

$dispconsolename

";

if($start == “” OR !is_numeric($start)) { $start = 0; }
$totallogs = countLogs();

$totalpages = round($totallogs/10);
$loglinks = “”;

if($totalpages > 1) {
for($i=0; $i<$totalpages; $i++) {
$startnum = $totallogs+(($i10)-$totallogs);
//echo "$i
10
";

$pagenum = $i+1;
$loglinks .= "Page $pagenum, ";
}
}

$query = "SELECT * FROM {$dbprefix}logs ORDER BY id DESC LIMIT $start,10 ";
$result = mysql_query($query)
or die(mysql_error());
while($row = mysql_fetch_array($result))
{
extract($row);
$datelogged = date(“n/j/Y g:i A”, $datelogged);
$action = stripslashes(textFilter($action));
echo "

"; }

echo "

Date: $datelogged
Action: $action


$loglinks

";

}

?>[/php]

The code:
[php]$startnum = $totallogs+(($i10)-$totallogs);
//echo "$i
10
";[/php]
change the number 10 to whatever the number of entries you want to display.

of course you will have to change the varibles and table info.

Sponsor our Newsletter | Privacy Policy | Terms of Service