Fatal error: Call to undefined method Paging::listaPagine()

leon-kennedy

Utente Attivo
19 Mag 2010
147
0
0
PHP:
<?
session_start();
//la classe per il paging
class Paging {
    private $totPag; //Totale Pagine nella tabella
    private $pagCorr; //Pagina corrente
    private $totRighe; //Totale righe nella tabella
    private $righePerPagina; //Numero di righe per pagina da ottenere

    //Facilita l'accesso all'array dell'intervallo
    const kIntervalloInizio='inizio';
    const kIntervalloLunghezza='lunghezza';

    // Il costruttore chiede quale sia la pagina corrente, il totale delle
    // righe in tabella e quante righe per pagina interessano
    public function __construct($pagCorr,$totRighe,$righePerPagina) {
        $this->pagCorr=$pagCorr;
        $this->totRighe=$totRighe;
        $this->righePerPagina=$righePerPagina;
        $this->totPag=$this->contaPagine($totRighe, $righePerPagina);
    }

    // Consente di modificare la pagina corrente con un'altra dopo
    // l'esecuzione del construct
    public function vaiAPagina($pagina){
        if($pagina==self::kUltimaPagina)
            $this->pagCorr=$this->totPag;
        elseif(is_numeric($pagina) and $pagina>1 and $pagina<$this->totPag)
            $this->pagCorr=$pagina;
        else
            $this->pagCorr=1;
    }

    //Indica in quante pagine viene divisa la tabella
    public function contaPagine($totRighe, $righePerPagina) {
        return ceil($totRighe / $righePerPagina);
    }

    //Restituisce un array indicante la posizione del primo record e quante
    //righe occorre scorrere
    public function dammiIntervallo() {
        return array(
            self::kIntervalloInizio => ($this->pagCorr-1) * $this->righePerPagina,
            self::kIntervalloLunghezza => $this->righePerPagina
        );
    }

//PREPARA L'OGGETTO PAGING E LO RITORNA
function CostruisciOggettoPaging($sql) {
    if (!isset($_GET['p']))
        $pagCorr = 1;
    else
        $pagCorr=$_GET['p'];

    $res = mysql_query($sql) or die('Err3');
    $totRighe = mysql_num_rows($res);
    mysql_free_result($res);
    $righePerPagina = 25;
    return new Paging($pagCorr, $totRighe, $righePerPagina);
}

//REALIZZA LA TABELLA E LA RITORNA SOTTO FORMA DI STRINGA
function CostruisciTabella($p,$sql) {
    $inter=$p->dammiIntervallo();
    $res = mysql_query("$sql limit {$inter[Paging::kIntervalloInizio]},{$inter[Paging::kIntervalloLunghezza]}") or die('Err4');
    ob_start();
    //Definizione della tabella
    echo <<<END
<table border="0" cellpadding="7px">
    <tr>
        <th>Nome</th>
        <th>Cognome</th>
        <th>Ruolo</th>
        <th>Et&agrave;</th>
        <th>Costo</th>
        <th>Squadra</th>
        <th>Tuffo</th>
        <th>Respinta</th>
        <th>Presa</th>
        <th>Reattivit&agrave;</th>
        <th>Resistenza</th>
    </tr>
END;
    while ($row = mysql_fetch_assoc($res)) {
    $row['id'];
    $id = $row['id'];
    $_SESSION['id_giocatore'] =  $id;
    $costo = number_format($row['costo'], "0", "", "."); 
    echo <<<END
    <tr>
        <td>{$row['nome']}</td>
        <td>{$row['cognome']}</td>
        <td>{$row['ruolo']}</td>
        <td>{$row['età']}</td>
        <td>$costo €</td>
        <td>{$row['squadra']}</td>
        <td>{$row['tuffo']}</td>
        <td>{$row['respinta']}</td>
        <td>{$row['presa']}</td>
        <td>{$row['reattività']}</td>
        <td>{$row['resistenza']}</td>
        <td><a href="azione_compra_port.php"><img src="immagini/icona_compra.jpg"></a></td>
    </tr>
END;
    }
    //Link di navigazione
    echo <<<END
    <th colspan="2">
        <a href="{$_SERVER['PHP_SELF']}?p={$p->precedentePagina()}">Indietro</a> |
        <a href="{$_SERVER['PHP_SELF']}?p={$p->prossimaPagina()}">Avanti</a>
    </th>
</table>
END;
     mysql_free_result($res);
     return ob_get_clean();
}



// mostriamo l'elenco delle pagine
  function listaPagine($pagCorr, $righePerPagina)
  {
    $listapgg = "";
    if (($pagCorr != 1) && ($pagCorr))
    {
      $listapgg .= " <a href=\"".SELF."?p=1\">Prima pag.</a> ";
    }
    if (($pagCorr-1) > 0)
    {
      $listapgg .= "<a href=\"".SELF."?p=".($pagCorr-1)."\"><</a> ";
    }
    for ($i=1; $i<=$righePerPagina; $i++)
    {
      if ($i == $pagCorr)
      {
        $listapgg .= "<b>".$i."</b>";
      }else{
        $listapgg .= "<a href=\"".SELF."?p=".$i."\">".$i."</a>";
      }
      $listapgg .= " ";
    }
    if (($pagCorr+1) <= $righePerPagina)
    {
      $listapgg .= "<a href=\"".SELF."?p=".($pagCorr+1)."\">></a> ";
    }
    if (($pagCorr != $righePerPagina) && ($righePerPagina != 0))
    {
      $listapgg .= "<a href=\"".SELF."?p=".$righePerPagina."\">Ultima pag.</a> ";
    }
    $listapgg .= "</td>\n";
    return $listapgg;
  }

  // permettiamo la navigazione per pagine precedenti e successive
  function precedenteSuccessiva($pagCorr, $righePerPagina)
  {
    $impaginazione = "";
    if (($pagCorr-1) <= 0)
    {
      $impaginazione .= "Precedente";
    }else{
      $impaginazione .= "<a href=\"".SELF."?p=".($pagCorr-1)."\">Pag. precedente</a>";
    }
    $impaginazione .= " | ";
    if (($pagCorr+1) > $righePerPagina)
    {
      $impaginazione .= "Prossima";
    }else{
      $impaginazione .= "<a href=\"".SELF."?p=".($pagCorr+1)."\">Prossima pag.</a>";
    }
    return $impaginazione;
  }

// definiamo la pagina di partenza
  function paginaIniziale($righePerPagina)
  {
    if ((!isset($_GET['p'])) || ($_GET['p'] == "1"))
    {
      $parti_da = 0;
      $_GET['p'] = 1;
    }else{
      $parti_da = ($_GET['p']-1) * $righePerPagina;
    }
    return $parti_da;
  }

$p = new Paging;

//mostriamo le pagine
$lista = $p->listaPagine($_GET['p'], $righePerPagina);
echo $lista . "<br>";




//connessione al database
include('../connect.php');

//estrazione dei giocatori
$sql="SELECT * FROM GIOC_giovani_port WHERE squadra='Senza contratto.' ORDER BY nome ASC";

$p = CostruisciOggettoPaging($sql);
$tabella_dati = CostruisciTabella($p,$sql);

mysql_close($conn);

echo $tabella_dati;
?>

Questo è l'errore che mi restituisce:
Fatal error: Call to undefined method Paging::listaPagine()

Sapete dirmi dove sbaglio? :)
 
La funzione listaPagine è definita fuori dalla classe. Quindi la dovresti richiamare così:
PHP:
$lista = listaPagine($_GET['p'], $righePerPagina);
E non così:
PHP:
$lista = $p->listaPagine($_GET['p'], $righePerPagina);
 

Discussioni simili