Visualizzazione dei risultati da 1 a 5 su 5

Discussione: Easy Paging script???

  1. #1

    Easy Paging script???

    Qualcuno conosce un codice per il paging facilmente implementabile??

    Ne ho provati un paio, ma un disatro.
    L'unico che funziona, estrapolato da un file demo_paging1.php
    funziona laddove nelle query al database non inserisco condizioni "WHERE"
    altrimenti sballa.
    Di conseguenza o mi restituisce tutti i risultati, visto che non posso usare opzioni:

    $query=" SELECT * FROM table limit $eu, $limit ";
    $result=mysql_query($query);


    oppure mi da i risultati della prima pagina e poi le altre , 2 e 3, sono bianche:

    $query=" SELECT * FROM table WHERE regione = '$regione' limit $eu, $limit ";
    $result=mysql_query($query);

    Lo script in realta esegue due query, una per sapere quanti risultati ci sono e l'altra
    per printarli poi a schermo.

    Qualcuno ha mai usato il paging e avesse da parte ancora il codice da poter modificare
    ed implementare sulla mia pagina??

  2. #2
    Ecco il codice della pagina.
    In rosso sono segnati le due query che mi sballano tutto se metto il WHERE (come ho fatto nell'esempio).



    <?
    //************************************************** **************************
    ////////////////////////Downloaded from www.plus2net.com //////////////////////////////////////////
    /////////////////////// Visit www.plus2net.com for more such script and codes.
    //////// Read the readme file before using /////////////////////
    //////////////////////// You can distribute this code with the link to www.plus2net.com ///
    ///////////////////////// Please don't remove the link to www.plus2net.com ///
    //////////////////////////
    //************************************************** ***************************
    ?>
    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <title>Plus2net.com paging script in PHP</title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
    <!--
    body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px;
    }
    -->
    </style></head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
    require "config.php"; // All database details will be included here
    ////////// delete for demo///
    //require "../tracking/z_db.php";
    connecttodb($servername,$dbname,$dbusername,$dbpas sword);
    function connecttodb($servername,$dbname,$dbuser,$dbpasswor d)
    {
    global $link;
    $link=mysql_connect ("$servername","$dbuser","$dbpassword");
    if(!$link){die("Could not connect to MySQL");}
    mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
    }
    $cerca=$_POST['cerca'];
    $dato=$_POST['dato'];
    $regione=$_POST['regione'];
    //////////

    $page_name="demo_paging1.php"; // If you use this code with a different page ( or file ) name then change this

    if(!isset($start)) { // This variable is set to zero for the first page
    $start = 0;
    }

    $eu = ($start - 0);
    $limit = 2; // No of records to be shown per page.
    $this1 = $eu + $limit;
    $back = $eu - $limit;
    $next = $eu + $limit;

    echo "<table width=\"100%\">";
    echo "<tr>";
    echo "<form name=cerca action='' method=post>";
    echo "<td >Azienda:<input type=\"text\" name=\"dato\">";

    echo "Regione: <select name=\"regione\" id=\"regione\" onchange=\"setCities(this)\">
    <option value=\"zz\" selected=\"selected\">------------</option>
    <option value=\"abbruzzo\">Abbruzzo</option>
    <option value=\"basilicata\">Basilicata</option>
    <option value=\"calabria\">Calabria</option>
    <option value=\"campania\">Campania</option>
    <option value=\"emilia romagna\">Emilia Romagna</option>
    <option value=\"friuli venezia giulia\">Friuli Venezia Giulia</option>
    <option value=\"lazio\">Lazio</option>
    <option value=\"liguria\">Liguria</option>
    <option value=\"lombardia\">Lombardia</option>
    <option value=\"marche\">Marche</option>
    <option value=\"molise\">Molise</option>
    <option value=\"piemonte\">Piemonte</option>
    <option value=\"bolzano\">Prov. aut. Bolzano</option>
    <option value=\"trento\">Prov. aut. Trento</option>
    <option value=\"puglia\">Puglia</option>
    <option value=\"sardegna\">Sardegna</option>
    <option value=\"sicilia\">Sicilia</option>
    <option value=\"toscana\">Toscana</option>
    <option value=\"umbria\">Umbria</option>
    <option value=\"valle d'aosta\">Valle d'Aosta</option>
    <option value=\"veneto\">Veneto</option>
    </select>";

    echo "Settore: <select name=\"settore\" id=\"settore\">
    <option value=\"\" selected=\"selected\">---------------</option>
    </select>";
    echo "<tr><td><input type=\"submit\" value=\"Invia\" name=\"rubrica\">";
    echo "<input type=\"reset\" value=\"RESET\" name=\"rubrica\"></FORM></td></tr></TABLE>";





    /////////////// WE have to find out the number of records in our table. We will use this to break the pages///////
    $query2=" SELECT * FROM dop WHERE regione = '$regione' ";
    $result2=mysql_query($query2);
    echo mysql_error();
    $nume=mysql_num_rows($result2);
    /////// The variable nume above will store the total number of records in the table////

    /////////// Now let us print the table headers ////////////////



    ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page///////////
    $query=" SELECT * FROM dop WHERE regione = '$regione' limit $eu, $limit ";
    $result=mysql_query($query);
    echo mysql_error();

    //////////////// Now we will display the returned records in side the rows of the table/////////
    while($noticia = mysql_fetch_array($result))
    {
    if($bgcolor=='#f1f1f1'){$bgcolor='#ffffff';}
    else{$bgcolor='#f1f1f1';}

    echo "<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#E2E2E2\">Nome Azienda:$noticia[nome_azienda]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#FFFFFF\">Indirizzo: $noticia[indirizzo]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#E2E2E2\">CAP: $noticia[cap]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#FFFFFF\">Città: $noticia[citta]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#E2E2E2\">Regione: $noticia[regione]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#FFFFFF\">Settore: $noticia[settore]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#E2E2E2\">Telefono: $noticia[telefono]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#FFFFFF\">Fax: $noticia[fax]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#E2E2E2\">Email: $noticia[email]</td>
    </tr>
    </table>";
    echo"<table width=\"300\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
    <tr>
    <td bgcolor=\"#FFFFFF\">Sito Web: $noticia[sito_web]</td>
    </tr>
    </table>";
    echo "

    ";}
    ////////////////////////////// End of displaying the table with records ////////////////////////

    ///////////////////////////////
    if($nume > $limit ){ // Let us display bottom links if sufficient records are there for paging

    /////////////// Start the bottom links with Prev and next link with page numbers /////////////////
    echo "<table align = 'center' width='30%'><tr><td align='left' width='30%'>";
    //// if our variable $back is equal to 0 or more then only we will display the link to move back ////////
    if($back >=0) {
    print "<font face='Verdana' size='2'>PREV</font>";
    }
    //////////////// Let us display the page links at center. We will not display the current page as a link ///////////
    echo "</td><td align=center width='30%'>";
    $i=0;
    $l=1;
    for($i=0;$i < $nume;$i=$i+$limit){
    if($i <> $eu){
    echo " <font face='Verdana' size='2'>$l</font> ";
    }
    else { echo "<font face='Verdana' size='4' color=red>$l</font>";} /// Current page is not displayed as link and given font color red
    $l=$l+1;
    }


    echo "</td><td align='right' width='30%'>";
    ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
    if($this1 < $nume) {
    print "<font face='Verdana' size='2'>NEXT</font>";}
    echo "</td></tr></table>";

    }// end of if checking sufficient records are there to display bottom navigational link.
    ?>

  3. #3
    Aggiungi al link, nella querystring, il valore che passi come ricerca alla query, altrimenti non puoi sapere cosa mettere nel campo WHERE....

    Guarda qui: http://forum.html.it/forum/showthrea...ostid=10653131
    Ciao!

  4. #4


    Non c'ho capito nulla. Non so neanche se mi sono spiegato bene.

    Se lascio il codice originario:

    [PHP]$query2=" SELECT * FROM dop ";
    $result2=mysql_query($query2);
    echo mysql_error();
    $nume=mysql_num_rows($result2);[PHP]

    e

    Codice PHP:
    $query=" SELECT * FROM dop  limit $eu$limit ";
    $result=mysql_query($query);
    echo 
    mysql_error(); 
    mi restituisce tutti i risultati con il numero di pagina sotto... quindi funziona, ma io non ho scelto cosa cercare.

    Se invece io sostituisco aggiungendo cosa voglio che sia selezionato in base ai campi riempiti ed ai menu a tendina:

    Codice PHP:
    if ($regione == "zz") {$query2"SELECT * FROM dop WHERE nome_azienda LIKE '%$dato%' ORDER BY nome_azienda ASC";}

    else {
    $query2"SELECT * FROM dop WHERE nome_azienda LIKE '%$dato%' AND regione like '$regione' AND settore like '%$settore%' ORDER BY nome_azienda ASC";}
    $result2=mysql_query($query2);
    echo 
    mysql_error();
    $nume=mysql_num_rows($result2); 
    e

    Codice PHP:
    if ($regione == "zz") {$query"SELECT * FROM dop WHERE nome_azienda LIKE '%$dato%' ORDER BY nome_azienda ASC limit $eu$limit ";}

    else {
    $query"SELECT * FROM dop WHERE nome_azienda LIKE '%$dato%' AND regione like '$regione' AND settore like '%$settore%' ORDER BY nome_azienda ASC limit $eu$limit ";}
    $result=mysql_query($query);
    echo 
    mysql_error(); 
    in questo caso mi da il giusto numero di pagine alla base e nella prima pagina i giusti risultati poi invece se faccio next o pag 2 o 3 non mi si visualizza nulla.


    Non ho capito cosa dovrei fare

  5. #5
    Certo, i valori che tu cerchi, la pagina li riceve solo nella prima pagina, mentre nelle altre, tu non invii più il valore della ricerca.

    Devi aggiungere al link della paginazione, i valori della ricerca, e poi elaborarli come se tu facessi una nuova ricerca ma con diversi valori limit.

    es:
    Codice PHP:
    $nome $_GET['nome'];
    $start $_GET['start'];
    $query "SELECT * FROM tabella WHERE nome LIKE '$nome' LIMIT $start$numero"# la esegui

    #a questo punto la pagina successiva la devi richiamare così:

    $link "pagina.php?nome=$nome&start=$start
    Puoi capire meglio se subito dopo che crei la query, fai un echo $query;

    e poi, lavora con i notice, magari vedi cosa ti manca: http://forum.mfweb.it/viewtopic.php?f=6&t=10
    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 © 2024 vBulletin Solutions, Inc. All rights reserved.