Ragazzi stavo leggendo la pillola presente sul forum e mi sono adoperato per adeguare il codice alle mie esigenze:
ho creato il file .class
codice:
class _makePager {
var $limit;
var $page;
var $numPages;
var $offset;
var $sql;
var $menu;
function _makePager ( $limit ) {
$this->limit = $limit;
}
function _getPagerData ( $numHits, $page ) {
$numHits = (int) $numHits;
$this->limit = max((int) $this->limit, 1);
$this->page = (int) $page;
$this->numPages = ceil($numHits / $this->limit);
$this->page = max($this->page, 1);
$this->page = min($this->page, $this->numPages);
$this->offset = ($this->page - 1) * $this->limit;
$this->sql = " LIMIT ".$this->offset.", ".$this->limit;
$this->_makeMenu();
}
function _makeMenu () {
if ($this->numPages>1) {
if ($this->page>1) $this->menu['PREVIOUS'] = ($this->page-1);
for ($i=1; $i<=$this->numPages; $i++) {
if ($i == $this->page) $this->menu['PAGES'][] = array (
'ID' => $i,
'STATUS' => false
);
else $this->menu['PAGES'][] = array (
'ID' => $i,
'STATUS' => true
);
}
if ($this->page<$this->numPages) $this->menu['NEXT'] = ($this->page+1);
}
}
function _getUri ( $_pagevar ) {
$_getvars = $_SERVER["QUERY_STRING"];
$_url = $_SERVER["PHP_SELF"]."?";
$_getvars = explode( "&", $_getvars );
for ($i=0; $i!=count($_getvars); $i++) {
list ($key, $value) = explode( "=", $_getvars[$i] );
if (($key)&&($value)) if ($key!=$_pagevar) $_url.= "{$key}={$value}&";
}
return "{$_url}{$_pagevar}=";
}
}
e poi nella pagina che estrae i risultati ho messo:
Codice PHP:
<?
require_once("php.sql.pager.class");
$_PAGER = new _makePager(2);
include("top_foot.inc.php");
include("config.inc.php");
top();
$db = mysql_connect($db_host, $db_user, $db_password);
$_sql = mysql_query("SELECT COUNT(*) FROM prodotti");
$_PAGER = _getPagerData(mysql_result($_sql),$_GET[p]);
$_sql = mysql_query("SELECT * FROM prodotti ORDER BY marca {$_PAGER->sql}");
while ($row = mysql_fetch_row($_sql)) {
// STAMPO I RISULTATI
echo "$row[marca]";
}
if ($_PAGER->menu['PREVIOUS']) echo "<a href=\"".$_PAGER->_getUri("p").$_PAGER->menu['PREVIOUS']."\">pagina precedente</a>";
$_PGS = $_PAGER->menu['PAGES'];
for ($j=0; $j!=count($_PGS); $j++) {
if ($_PGS[$j]['STATUS']) echo " [ <a href=\"".$_PAGER->_getUri("p").$_PGS[$j]['ID']."\">{$_PGS[$j]['ID']}</a> ] ";
else echo $_PGS[$j]['ID'];
}
if ($_PAGER->menu['NEXT']) echo "<a href=\"".$_PAGER->_getUri("p").$_PAGER->menu['NEXT']."\">pagina successiva</a>";
mysql_close($db);
foot();
?>
Se testo questa pagine esce l'errore: Call to undefined function: _getpagerdata()
WHy?