Ciao a tutti, io ho il seguente codice per scorrere i record:
Codice PHP:
function getPagerData($numHits, $limit, $page) {
$numHits = (int) $numHits; //
$limit = max((int) $limit, 1); //convalidano la funzione di input: evitano divisioni per 0
$page = (int) $page; //
$numPages = ceil ($numHits / $limit); //calcola il numero delle pagine
$page = max($page, 1); //se il numero delle pagina è minore a 1, lo imposta come "1"
$page = min($page, $numPages); //se il numero della pagina è maggiore del numero totale delle pagine, lo imposta sull'ultimo numero disponibile delle pagine
$offset = ($page - 1) * $limit; //calcola l'offset
$ret = new stdClass; //
//
$ret->offset = $offset; //
$ret->limit = $limit; //sviluppa un piccolo oggetto di ritorno
$ret->numPages = $numPages; //
$ret->page = $page; //
//
return $ret;
}
// get the pager input values
$page = $_GET['page'];
$limit = 7;
$sql_c = "SELECT ID_RISP FROM BACHECHE_RISPOSTE WHERE TOPIC_RISP = $ID_TOPIC";
$result = mysql_query($sql_c,$connessione);
$total = mysql_num_rows($result);
if ($total == 0) $total = 1;
// work out the pager values
$pager = getPagerData($total, $limit, $page);
$offset = $pager->offset;
$limit = $pager->limit;
$page = $pager->page;
// output del sistema di impaginazione
if ($page == 1 or $offset < 0){ // this is the first page - there is no previous page
echo "<< | ";
}
else{ // not the first page, link to the previous page
echo "<a href=\"$_SERVER[PHP_SELF]?page=" . ($page - 1) . "&id_topic=$ID_TOPIC\" class='notstandard'><<</a> | ";
}
for ($i = 1; $i <= $pager->numPages; $i++) {
if ($i == $pager->page){ // pagina attuale
echo "$i";
}
else{
echo "<a href=\"$_SERVER[PHP_SELF]?page=$i&id_topic=$ID_TOPIC\" class='notstandard'>$i</a>";
}
echo " | ";
}
if ($page == $pager->numPages){ // this is the last page - there is no next page
echo ">>";
}
else{ // not the last page, link to the next page
echo "<a href=\"$_SERVER[PHP_SELF]?page=" . ($page + 1) . "&id_topic=$ID_TOPIC\" class='notstandard'>>></a>";
}
ok, ora però se ho troppe pagine mi viene una lista infinita di numeri...
quale potrebbe essere il codice più adatto per far uscire una cosa del tipo
codice:
<< | 1 | 2 | ... | 7 | ... | 34 | 35 | >>
[dove 7 è la pagina che stiamo vedendo in questo momento]
?????
Spero in un aiuto.
Grazie in anticipo ^_^