Location: PHPKode > scripts > Split Result > split-result/split_result.php
<?
// Spliter Class
//
// Author: Gaidar I Magdnurov [hide@address.com]
// Created: 07/27/2001
// Modified: 07/27/2003
// License: GNU

class SplitResult{

	var $result; // link to result from mysql ($this->result)
	var $max_rows; // max rows by page ($this->max_lines)
	var $rows; // number of rows in pages ($this->rows)
        var $menu_items;
	
function SplitResult($new_result, $new_max = 10, $new_menu_items = 5)
{
	$this->max_rows = $new_max;
	$this->result = $new_result;
        $this->menu_items
	@$this->rows = mysql_num_rows($this->result); // numbers of rows in result
	return 1;
}

function content($page = 1)
{
	if($page < 1) $page = 1;
	if($page > $this->num_pages()) $page = $this->num_pages();
	
	// return content of page
	$i_min = ($page - 1) * $this->max_rows;
	$i_max = $i_min + $this->max_rows;
	if($i_max > $this->rows) $i_max = $this->rows;

	for($i = 0; $i <= $i_max - 1; $i++)
	{
		$m_row = mysql_fetch_array($this->result);
		if($i >= $i_min){
			$ret_arr[] = $m_row; // add row array to results array
		}
	}	
return $ret_arr;
}

function num_pages()
{
	$num = round($this->rows / $this->max_rows);
	if($num < ($this->rows / $this->max_rows)) $num++;
	return $num;
}

function menu($current_page = 1, $href)
{
 $menu = '<!-- Navigation Menu -->'; // Debug line for HTML

	if($current_page < 1) $current_page = 1;
	if($current_page > $this->num_pages()) $current_page = $this->num_pages();

if($current_page > 1){ $menu.='<a href="'.$href.($current_page - 1).'">&lt;&lt;</a>&nbsp;|&nbsp;'; }else{ $menu.='&lt;&lt;&nbsp;|&nbsp;'; }

// Limit size of menu
$first_link = 1;
$last_link = 11;

if ($current_page > 5){
	$first_link = $current_page - $this->menu_items;
	$last_link  = $current_page + $this->menu_items;
}

//for($i = 1; $i <= $this->num_pages(); $i++)
for($i = $first_link; $i <= $last_link; $i++)
{
	if($current_page == $i){
		$menu.='<b>'.$i.'</b>&nbsp;|&nbsp;';
	}else{
		$menu.='<a href="'.$href.$i.'">'.$i.'</a>&nbsp;|&nbsp;';
	}
}

if($current_page < $this->num_pages()){ $menu.='<a href="'.$href.($current_page + 1).'">&gt;&gt;</a>'; }else{ $menu.='&gt;&gt;'; }

return $menu;
}

} // class end 

?>
Return current item: Split Result