inserire una classe pager

salve a tutti , dovrei inserire una classe pager ,che ho scaricato dal sito phpclasses.org , adesso io con le clasi non ho dimestichezza, e non riesco a estrarre i dati dal database tramite la classe sarebbe a dire limite numero di date e numero di utenti per pagina .. spero che qualcuno di voi mi possa aiutare mostrandomi come inserire una classe dentro la query . comunque posto l ' esempio , e la classe

esempio

<?php
//pager example
$conn = mysql_connect("localhost", "root", "maurizio");
$db = mysql_select_db("supp");
include('class.pager.php');

$array = mysql_query("SELECT * FROM tech where staffid = staffid ");
$result = mysql_num_rows($array);
$num_results = $result ; //this value should arrive from some database query, like "select count(id) from table_you_want_to_page" 
$per_page = 1; //number of results to be shown per page
$query_string = "class.pager.example.php?"; // current file.. 
$pager = new pager($num_results, $per_page, $query_string); //building a pager
$sql = mysql_query("SELECT * FROM tech limit {$pager->num_results},{$pager->page_list_size} ,{$pager->per_page}");
while($row = mysql_fetch_assoc($sql) )
{
echo $row['nome'].'-'. $row['cognome'].'-'. $row['username'].'<br><br><br><br><br><br>';
}
echo "Pager example: Dividing {$pager->num_results} results into {$pager->page_list_size} pages showing {$pager->per_page} results per page<br><br>";

$pg = $pager->page; //getting active page 

echo "<br>Active page " . $pg;

echo "<br><br> Page list: ";
echo $pager->getButPrev($pg); // get PREVIOUS button
if($pager->getButPrev($pg)) echo $pager->separator; //show a default seperator between PREVIOUS button and page list IF previous button is visible
$range = 9; //set the range of page button list
echo $pager->getButList($range); //display page buttons.. 1 2 3 4 5 etc
if($pager->getButNext($pg)) echo $pager->separator; //show a default seperator between page list and NEXT button IF next button is visible
echo $pager->getButNext($pg); //get NEXT button
echo "<br>";

echo $pager->getRangeInfo(); // print "showing results x - y of z" 

//some design tuning!
$pager->but_prev = "<a href=\"{query_string}&page={page}\"><strong>&lt;&lt; ({page})</strong></a>";
$pager->but_next = "<a href=\"{query_string}&page={page}\"><strong>({page}) &gt;&gt;</strong></a>";
$pager->but_page = "<a href=\"{query_string}&page={page}\">[Page: {page}]</a>";
$pager->but_page_this = "[Active page: {page}]";
$pager->separator = ".";
$pager->range_display = "You see results: {from} to {to} out of {total}";

//now redraw..
echo "<br><br> Retuned Page list: ";
echo $pager->getButPrev($pg);
if($pager->getButPrev($pg)) echo $pager->separator; 
echo $pager->getButList(6); 
if($pager->getButNext($pg)) echo $pager->separator; 
echo $pager->getButNext($pg); 
echo "<br>";
echo $pager->getRangeInfo();



echo "<br><br>Extra info:<br><br>";

for($i = 1; $i <= $pager->page_list_size; $i++){
echo "Page " . $i;
echo " -> Offset in db query: ";
echo $pager->getPageFrom($i);
echo "<br>";
}

?>

e questa e la classe<?

/** * Pager class * For doing the page-related math and generating page links (prev 1 2 3 4 5 next etc. ). * * @package Pager * @author spyefex <tomas@netatbiz.com> * @version 1.0 * @copyright (c)2004, Net@Biz */

class pager { /** * Number of results to show per one page * @var int */ var $per_page; /** * Currently active page * @var int */ var $page; /** * Page text in query string * @var string */ var $page_identifier; /** * NEXT button html code template * "{query_string}" and "{page}" will be automatically replaced by the appropriate values * @var string */ var $but_next = "<a href=\"{query_string}&page={page}\">next</a>";

/** * PREVIOUS button html code template * "{query_string}" and "{page}" will be automatically replaced by the appropriate values * @var string */ var $but_prev = "<a href=\"{query_string}&page={page}\">prev</a>"; /** * Page ( ie.: 1, 2, 3, or 4, etc. ) button html code template * "{query_string}" and "{page}" will be automatically replaced by the appropriate values * @var string */ var $but_page = "<a href=\"{query_string}&page={page}\">{page}</a>"; /** * Currently active page button html code template * "{query_string}" and "{page}" will be automatically replaced by the appropriate values * @var string */ var $but_page_this = "<strong>{page}</strong>"; /** * Separator template * Will be included among page buttons in page list * @var string */ var $separator = " - "; /** * Range display template * "{from}", "{to}" and "{total}" will be automatically replaced by the appropriate values * @var string */ var $range_display = "Showing results {from} - {to} of {total} "; /** * Total number of results * @var int */ var $num_results; /** * Number of pages currently available * @var int */ var $page_list_size; /** * Initial query string for use in button links * Including "file.php?" (Ie.: "index.php?location=heaven") * @var string */ var $query_string; /** * Pager initialization * * @param int $num_results total number of results ( you should get this from database before constructing the pager object ) * @param int $per_page number of results to display in one page * @param string $query_string initial query string ( if you are using this pager to display search results, $query_string should arrive dynamically according to search query ) * @param string $page_id page identifier variable in query string (ie.: "pg"); */ function pager($num_results, $per_page = 10, $query_string = '', $page_id = "page") { $this->page = isset( $_REQUEST[$page_id] )? $_REQUEST[$page_id] : 1; $this->page_identifier = $page_id; $this->per_page = $per_page; $this->num_results = $num_results; $this->query_string = $query_string; $this->page_list_size = @ceil( $num_results / $per_page ); } /** * Gets the result offset for a page. * NOTICE: If you want to use this function to * show the logically correct value for output in html (Ie.: "showing results 1 - 10"), * you should increase the result of this function by 1 (because in real life results * start from 1, not from 0) * * @param int $page the page you want to get the offset for * @returns int */ function getPageFrom($page) { if($page <= 0) return 0; if($page > $this->page_list_size) return 0; $result = ($page-1) * $this->per_page; $result = ($result >= $this->num_results) ? ($this->num_results - 1) : $result; return $result; } /** * Gets the tail value of results shown in a page. * NOTICE: Do NOT use the results of * this function in database query, it's for outputting the range only. * (Ie.: "showing results 1 - 10") * * @param int $page the page you want to get the tail for * @returns int */ function getPageTo($page) { if($page <= 0) return 0; if($page > $this->page_list_size) return 0; $result = ($page-1) * $this->per_page + $this->per_page; $result = ($result >= $this->num_results) ? $this->num_results : $result; return $result; } /** * Generates the NEXT button html code from the predefined template * (check initial vars for more information) * * @param int $page the page you want to get the NEXT button for ( usually the active page ) * @returns string */ function getButNext($page) { $page++; if($page > $this->page_list_size) return ""; if($page < 1) return ""; $temp = ereg_replace("{query_string}", $this->query_string, $this->but_next); $result = ereg_replace("{page}", (string)$page, $temp); return $result; }

/** * Generates the PREVIOUS button html code from the predefined template * (check initial vars for more information) * * @param int $page the page you want to get the PREVIOUS button for ( usually the active page ) * @returns string */ function getButPrev($page) { $page--; if($page < 1) return ""; if($page > $this->page_list_size) return ""; $temp = ereg_replace("{query_string}", $this->query_string, $this->but_prev); $result = ereg_replace("{page}", (string)$page, $temp); return $result; } /** * Generates the PAGE button html code from the predefined templates * (check initial vars for more information) * * @param int $page the page you want to get the PAGE button for * @returns string */ function getButPage($page) { if($page < 1) return ""; if($page > $this->page_list_size) return ""; $source = ($page == $this->page) ? $this->but_page_this : $this->but_page; $temp = ereg_replace("{query_string}", $this->query_string, $source); $result = ereg_replace("{page}", (string)$page, $temp); return $result; } /** * Generates the Google style PAGE button list html code from the predefined templates * (ie.: "1 - 2 - 3 - 4 - 5", check initial vars for more information) * * @param int $range number of page buttons to be shown before and after tbe current page * @returns string */ function getButList($range = 9) { $range++; unset($result); for($i = ($this->page - $range); $i <= ($this->page + $range); $i++) { if($this->page < $range) { $result .= $this->getButPage($i); if ($i == $range) break; } else $result .= $this->getButPage($i); if($this->getButPage($i+1) && $result && $i < $this->page + $range) $result .= $this->separator; } return $result; } /** * Generates the result range information text from the predefined template * (ie.: "Displaying 1 - 3 of 24", check initial vars for more information) * * @returns string */ function getRangeInfo() { $from = $this->getPageFrom($this->page) + 1; $to = $this->getPageTo($this->page); $temp = ereg_replace("{from}", (string)$from, $this->range_display); $temp = ereg_replace("{to}", (string)$to, $temp); $result = ereg_replace("{total}", (string)$this->num_results, $temp); return $result; } } ?>

inviato 7 anni fa
roccochiolo
X 0 X

ciao,

prova questA:

http://www.sv-design.org/blog/php-mysql-paginazione-dati/

Io lo usata funziona benissimo..

risposto 7 anni fa
luik
luik
1
modificato 7 anni fa
X 0 X

Qui trovi teoria e pratica:

http://www.phpnews.it/articoli/paginazione-dei-dati/

:bye:

risposto 7 anni fa
Gianni Tomasicchio
X 0 X
Effettua l'accesso o registrati per rispondere a questa domanda