Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14

Discussione: paginazione php

  1. #1

    paginazione php

    Buongiorno a tutti quanti e soprattutto buona domenica.
    Nel codice sottostante non riesco a mettere i vari titoli degli articoli elencati linkabili... Qualcuno mi darebbe una mano

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Documento senza titolo</title>
    </head>


    <body>
    <?php
    include("config.inc.php");
    $db= mysql_connect($db_host, $db_user, $db_password);
    mysql_select_db($db_name, $db);

    $rowsPerPage = 4;

    $pageNum = 1;

    if(isset($_GET['page']))
    {
    $pageNum = $_GET['page'];
    }

    $offset = ($pageNum - 1) * $rowsPerPage;

    $query = "SELECT id, data, titolo FROM Articoli LIMIT $offset, $rowsPerPage";
    $result = mysql_query($query, $db);

    while ($row = mysql_fetch_array($result))
    {
    while(list($id, $data, $titolo) = mysql_fetch_array($result))
    {
    echo "<a href=\"articolo_leggi.php?id=$row[id]\">" . "$row[data]" . "$row[titolo]</a>
    ";
    }
    }
    echo '
    ';

    $query = "SELECT COUNT(id) AS numrows FROM Articoli";
    $result = mysql_query($query, $db);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    $numrows = $row['numrows'];

    $maxPage = ceil($numrows/$rowsPerPage);

    $self = $_SERVER['PHP_SELF'];


    if ($pageNum > 1)
    {
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
    }
    else
    {
    $prev = ' [Prev] ';
    $first = ' [First Page] ';
    }

    if ($pageNum < $maxPage)
    {
    $page = $pageNum + 1;
    $next = " <a href=\"$self?page=$page\">[Next]</a> ";

    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
    }
    else
    {
    $next = ' [Next] ';
    $last = ' [Last Page] ';
    }

    echo $first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last;

    ?>
    </body>
    </html>

    Ringrazio anticipatamente.
    Ciao.
    FRANCESCO
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  2. #2
    Ehiiii ci sono quasi saltato fuori... posto il codice per, ovviamente, pubblica utilità.
    Il problema è che non mi visualizza il primo e l'ultimo record inserito... qualcuno mi aiuta?

    Questo è il nuovo codice appena appena sfornato...

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Documento senza titolo</title>
    </head>
    <body>
    <?php
    include("config.inc.php");
    $db= mysql_connect($db_host, $db_user, $db_password);
    mysql_select_db($db_name, $db);
    $rowsPerPage = 4;
    $pageNum = 1;
    if(isset($_GET['page']))
    {
    $pageNum = $_GET['page'];
    }
    $offset = ($pageNum - 1) * $rowsPerPage;
    $query = "SELECT id, data, titolo FROM Articoli WHERE anno='2008' ORDER BY id DESC LIMIT $offset, $rowsPerPage";
    $result = mysql_query($query, $db);


    while(list($id, $data, $titolo) = mysql_fetch_array($result))
    {
    while ($row = mysql_fetch_array($result))
    {
    echo "<a href=\"articolo_leggi.php?id=$row[id]\">" . "$row[data]" . "$row[titolo]</a>
    ";
    }
    }
    echo '
    ';

    $query = "SELECT COUNT(id) AS numrows FROM Articoli";
    $result = mysql_query($query, $db);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    $numrows = $row['numrows'];

    $maxPage = ceil($numrows/$rowsPerPage);

    $self = $_SERVER['PHP_SELF'];


    if ($pageNum > 1)
    {
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
    }
    else
    {
    $prev = ' [Prev] ';
    $first = ' [First Page] ';
    }

    if ($pageNum < $maxPage)
    {
    $page = $pageNum + 1;
    $next = " <a href=\"$self?page=$page\">[Next]</a> ";

    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
    }
    else
    {
    $next = ' [Next] ';
    $last = ' [Last Page] ';
    }

    echo $first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last;

    ?>
    </body>
    </html>


    Tra l'altro l'impaginazione è veramente fantastica dato che sotto gli articoli compare quanto segue:

    [First Page] [Prev] Showing page 1 of 2 pages [Next] [Last Page]

    Il visitatore riesce a navigare efficientemente.
    Ciao e buona serata a tutti.
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  3. #3
    nessuno riesce a darmi un aiutino?
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  4. #4
    Ce l'ho fatta da solo...
    ragazzi posto il codice funzionante al 100% in modo tale che possa esser utilizzato.
    Tale codice, ricordo, elenca la data e il titolo degli articoli scritti e permette di impostare un numero max di articoli x pagina. La navigazione risulta molto buona


    [First Page] [Prev] Showing page 1 of 2 pages [Next] [Last Page]


    Ecco il codice:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Documento senza titolo</title>
    </head>
    <body>

    <?php
    include("config.inc.php");
    $db= mysql_connect($db_host, $db_user, $db_password);
    mysql_select_db($db_name, $db);
    $rowsPerPage = 4;
    $pageNum = 1;
    if(isset($_GET['page']))
    {
    $pageNum = $_GET['page'];
    }
    $offset = ($pageNum - 1) * $rowsPerPage;
    $query = "SELECT id, data, titolo FROM Articoli WHERE anno='2008' ORDER BY id DESC LIMIT $offset, $rowsPerPage";
    $result = mysql_query($query, $db);

    while(list($row[id], $row[data], $row[titolo]) = mysql_fetch_array($result))
    {
    echo "<a href=\"articolo_leggi.php?id=$row[id]\">" . "$row[data]" . "$row[titolo]</a>
    ";
    }

    echo '
    ';
    $query = "SELECT COUNT(id) AS numrows FROM Articoli";
    $result = mysql_query($query, $db);
    $row = mysql_fetch_array($result, MYSQL_ASSOC);
    $numrows = $row['numrows'];
    $maxPage = ceil($numrows/$rowsPerPage);
    $self = $_SERVER['PHP_SELF'];

    if ($pageNum > 1)
    {
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";

    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
    }
    else
    {
    $prev = ' [Prev] ';
    $first = ' [First Page] ';
    }
    if ($pageNum < $maxPage)
    {
    $page = $pageNum + 1;
    $next = " <a href=\"$self?page=$page\">[Next]</a> ";

    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
    }
    else
    {
    $next = ' [Next] ';
    $last = ' [Last Page] ';
    }
    echo $first . $prev . " Showing page $pageNum of $maxPage pages " . $next . $last;
    ?>
    </body>
    </html>
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  5. #5
    Volevo porre un quesito in merito al codice sopra
    Se premo il link del titolo giustamente mi fa leggere l'articolo x intero. Se sono alla pagina 52 di 100 quando torno indietro mi fa andare alla pagina 1 di 100...
    come posso fare?????

    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  6. #6
    nessuno?
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  7. #7
    Utente di HTML.it L'avatar di alpeweb
    Registrato dal
    Oct 2002
    Messaggi
    1,691
    Quando torni indietro come?
    ...altri 5 anni di purga...

  8. #8
    Non c'è un comando che crei l'effetto torna indietro del browser... così risolverei i problemi!!!
    Francesco
    http://www.cubamylove.com
    http://www.casadamarys.com
    Cuba Trinidad

  9. #9
    Utente di HTML.it L'avatar di alpeweb
    Registrato dal
    Oct 2002
    Messaggi
    1,691
    bisogna che ti passi sempre la variabile dell'offset
    ...altri 5 anni di purga...

  10. #10
    Originariamente inviato da alpeweb
    bisogna che ti passi sempre la variabile dell'offset
    oppure (sconsigliatissimo) fai un Vai indietro

    ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.