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? :)
 

alessandro1997

Utente Attivo
6 Ott 2009
5.302
1
0
26
Roma
alessandro1997.netsons.org
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
Autore Titolo Forum Risposte Data
L [PHP] Fatal error: Call to a member function prepare() on null in PHP 0
C [PHP] Errore "Fatal error: Call to undefined function getTotalUsers()" PHP 2
U [PHP] Fatal error: Call to a member function Query() PHP 1
G Fatal error: Uncaught Error: Call to undefined method UserController PHP 0
O Fatal error: Call to undefined function testNome() in C:\xampp\...\...\index.php on line 51 PHP 4
JackIlPazzo Fatal error: Call to a member function execute() on a non-object PHP 2
JackIlPazzo PHP: Fatal error: Call to a member function bind_param() on a non-object PHP 0
P Fatal error: Call to undefined method SMTP::setTimeout() PHP 4
M fatal error: Call to undefined function gdrcd_filter() PHP 6
T Fatal error: Call to a member function show_crom() on a non-object PHP 1
F Fatal error: Call to undefined function PHP 9
L Fatal error: Call to undefined function virtual() in C:\Inetpub\wwwroot\... PHP 1
U Campo vuoto data errore Fatal error: PHP 2
I Fatal error: Query Failed! SQL: SELECT * INTO OUTFILE PHP 1
D [PHP] Fatal error: Class 'COM' not found in C:\..... PHP 6
T [PHP] aiuto....Fatal error: Uncaught Error:non riesco a capire PHP 1
J [PHP] Recoverable fatal error: PHP 4
J [PHP] fatal error PHP 1
C PHP errore Fatal Error: Allowed Memory Size of ... Bytes Exhausted PHP 7
Antoyosh Fatal error con Wordpress WordPress 5
filippino Fatal error: Cannot redeclare (function) PHP 2
C errore su wordpress _ fatal error PHP 1
S [RISOLTO] Fatal error in Upload Multiplo di immagini PHP 2
F Fatal error: t3import not found object Joomla 0
Mauro Guardiani Fatal error HTML e CSS 2
T Fatal error: Cannot access empty property PHP 2
G Fatal error: Uncaught exception 'PDOException' PHP 12
LaKanka Fatal error upload immagini PHP 19
S 404 Error " Page not Find" Error SEO e Posizionamento 0
L Error Code: 1215. Cannot add foreign key constraint MySQL 3
M HTTP Status 500 - Internal Server Error. Java 0
A Uncaught Error: jQuery 1
F Uncaught (in promise) Error: 3000ms timeout exceeded Javascript 0
W ADODB.Recordset error '800a0bb9' Classic ASP 2
D error text in table HTML e CSS 11
W Microsoft OLE DB Provider for Visual FoxPro error '80040e14' Function name is missing ). Classic ASP 0
W Parse error: syntax error, unexpected '$result' (T_VARIABLE) PHP 4
W Errore di run-time di Microsoft VBScript error '800a0035' Impossibile trovare il file Classic ASP 0
G Upload file error Apache 0
A Server Apache immagine not found (ERROR 404) Apache 5
T MySQL ERROR 1064 MySQL 1
T [PHP] ...Parse error che non c'è... PHP 7
V [MySQL] You have an error in your SQL syntax MySQL 1
G PHPMailer: SMTP error Gmail PHP 8
G [WordPress] [PHP] Parse error: syntax error, unexpected '$x332cbce1' WordPress 2
I [PHP] Login Facebook SDK returned an error: No URL set! PHP 0
bubino8 [PHP] Query syntax error PHP 6
momeraths [WordPress] cURL error: problema aggiornamento/installazione plugin WordPress 4
A [PHP] FPDF error: Some data has already been output, can't send PDF file PHP 5
otto9due Error anomalo durante invio dati $.ajax Ajax 20

Discussioni simili