Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    xché con PHP l' impaginazione è difficile !!!!!!!!

    Salve,
    qualcuno potrebbe darmi una MANO ?
    non capisco xché si comporta in questo modo il sistema di impaginazione di un database con circa 20.000 records.
    In pratica, via query comando di visualizzare soltanto i record che rientrino in una data specifica e come nella foto tutti i record datati 02/08/2004. Il problema consiste nel fatto che lo script mi propone comunque tutti i link alle pagine che teoricamente contengono record secondo le specifiche della query.
    I Record con tale data sono presenti soltanto nelle prime 5 pagine; come mai lo script mi propone circa 700 links ?


    Codice PHP:

    // get the pager input values 
    $page $_GET['page']; 
    $limit 30;

    $result mysql_query("select count(*) from $table");
    $total mysql_result($result00);

    // work out the pager values 
    $pager Pager::getPagerData($total$limit$page); 
    $offset $pager->offset
    $limit $pager->limit
    $page $pager->page;

    // use pager values to fetch data 
    $query "SELECT * "
            
    " FROM $table "
            
    " WHERE data = \"02/08/2004\" LIMIT $offset$limit";
    //$query = "select * from $table order by id limit $offset, $limit";
    $result mysql_query($query);

    // output page content

              
    while (list($id$data$ora$terminale$originalcode) = mysql_fetch_row ($result)) {

            echo 
    " <table border=\"0\" cellspacing=\"1\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"500\">\n".
                 
    " <tr>".
                 
    " <td width=\"100\">[b]ID[/b]</td>\n".
                 
    " <td width=\"381\">$id</td>\n".
                 
    " </tr>\n".
                 
    " <tr>\n".
                 
    " <td width=\"100\">[b]Data[/b]</td>\n".
                 
    " <td width=\"381\">$data</td>\n".
                 
    " </tr>\n".
                 
    " <tr>\n".
                 
    " <td width=\"100\">[b]Orario[/b]</td>\n".
                 
    " <td width=\"381\">$ora</td>\n".
                 
    " </tr>\n".
                 
    " <tr>\n".
                 
    " <td width=\"100\">[b]Terminale[/b]</td>\n".
                 
    " <td width=\"381\">$terminale</td>\n".
                 
    " </tr>\n".

                 
    " </table>\n".
                 


    \n\n"
    ;

          }





    // output paging system (could also do it before we output the page content) 
    if ($page == 1// this is the first page - there is no previous page 
    echo "Previous"
    else 
    // not the first page, link to the previous page 
    echo "<a href=\"paging.php?page=" . ($page 1) . "\">Previous</a>";

    for (
    $i 1$i <= $pager->numPages$i++) { 
    echo 
    " | "
    if (
    $i == $pager->page
    echo 
    "Page $i"
    else 
    echo 
    "<a href=\"paging.php?page=$i\">Page $i</a>";
    }

    if (
    $page == $pager->numPages// this is the last page - there is no next page 
    echo "Next"
    else 
    // not the last page, link to the next page 
    echo "<a href=\"paging.php?page=" . ($page 1) . "\">Next</a>";
    ?> 
    IMPOSSIBLE IS NOTHING - LOOK BEFORE YOU LEAP !!!

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2003
    Messaggi
    534
    penso che sia dato dal fatto che conti "tutti" i record:

    $result = mysql_query("select count(*) from $table");
    $total = mysql_result($result, 0, 0);

    $pager = Pager::getPagerData($total, $limit, $page);
    $offset = $pager->offset;
    $limit = $pager->limit;
    $page = $pager->page;


    prova ad usare la stessa condizione che usi dopo:

    select count(*) from $table WHERE data = \"02/08/2004\"



  3. #3
    Ho risolto in questo modo:

    Codice PHP:

    $periodo 
    ="02/08/2004";

    $result mysql_query("select count(*) from $table WHERE data=\"$periodo\""); 
    B R A V I S S I M O . Thank you !!!
    IMPOSSIBLE IS NOTHING - LOOK BEFORE YOU LEAP !!!

  4. #4
    Ciao, scusami ancora,

    esiste un modo meno complicato per realizzare la stessa impaginazione ma con la visualiazzazione massima di 5 link alle pagine successive come fa questo forum:



    Come devo modificare il mio codice:


    Codice PHP:


    // output paging system (could also do it before we output the page content) 
    if ($page == 1// this is the first page - there is no previous page 
    echo "Previous ";
    else 
    // not the first page, link to the previous page 
    echo "[b]<a href=\"paging.php?page=" . ($page 1) ."&date=$periodo"\">[Previous]</a>[/b]";

    for (
    $i 1$i <= $pager->numPages$i++) { 
    echo 
    " | "
    if (
    $i == $pager->page
    echo 
    "Page $i";
    else 
    echo 
    "<a href=\"paging.php?page=$i&date=$periodo\">Page $i</a>";
    }

    if (
    $page == $pager->numPages// this is the last page - there is no next page 
    echo " Next";
    else 
    // not the last page, link to the next page 
    echo "[b]<a href=\"paging.php?page=" . ($page 1) ."&date=$periodo"\">[Next]</a>[/b]"
    IMPOSSIBLE IS NOTHING - LOOK BEFORE YOU LEAP !!!

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.