Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323

    Paginazione Php - Mysql

    Ciao a tutti, io vorrei farmi una paginazione del tipo

    www.miosito.com/1 <- PAGINA 1
    www.miosito.com/2 <- PAGINA 2

    e non www.miosito.com?page=1
    e non www.miosito.com?page=2


    Qualcuno sa come si potrebbe fare?

    Io ho gia' una classe in cui leggo i valori dell'URL (es. test.php/primo/secondo/...) e riesco a ricavare i valori PRIMO e SECONDO e cosi' via



    Grazie a tutti

  2. #2

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    vorrei evitare il mod_rewrite !!!
    Io ho una classe che legge l'URL. Poi ho un'altra classe che fa la paginazione. Ma come ho scritto io mi vien fuori cosi' l'URL

    www.miosito.com/1 <- se l'utente si trova alla pagina 1, mentre se clicca pagina 2 vien fuori cosi' : www.miosito.com/1/2 e non so come mai.

    Certe volte vien fuori www.miosito.com//2 con il doppio // ma funziona lo stesso e va a pagina 2. Invece il problema consiste nel fatto che se l'utente clicca next (trovandosi alla pagina 2) vien fuori questo www.miosito.com/2/3 e se clicca ancora next vien fuori www.miosito.com/2/3/3 non so come mai. Volevo usare un header location ma non funziona. Se qualcuno ha un'idea é ben accetta



    posto il codice:

    include('uri.php');


    class pagination {

    var $fullresult;
    var $totalresult;
    var $query;
    var $resultPerPage;
    var $resultpage;
    var $pages;
    var $openPage;

    function createPaging($query,$resultPerPage)
    {

    $uri = new uri;
    $uri->fetch_uri_string();
    $uri->explode_segments();
    $page = $uri->segment(0);

    $this->query = $query;
    $this->resultPerPage= $resultPerPage;
    $this->fullresult = mysql_query($this->query);
    $this->totalresult = mysql_num_rows($this->fullresult);
    $this->pages = $this->findPages($this->totalresult,$this->resultPerPage);
    if(isset($page) && $page>0) {
    $this->openPage = $page;
    if($this->openPage > $this->pages) {
    $this->openPage = 1;
    }
    $start = $this->openPage*$this->resultPerPage-$this->resultPerPage;
    $end = $this->resultPerPage;
    $this->query.= " LIMIT $start,$end";
    }
    elseif($page>$this->pages) {
    $start = $this->pages;
    $end = $this->resultPerPage;
    $this->query.= " LIMIT $start,$end";
    }
    else {
    $this->openPage = 1;
    $this->query .= " LIMIT 0,$this->resultPerPage";
    }
    $this->resultpage = mysql_query($this->query);
    }

    function findPages($total,$perpage)
    {
    $pages = intval($total/$perpage);
    if($total%$perpage > 0) $pages++;
    return $pages;
    }


    function displayPaging()
    {
    $self = $_SERVER['PHP_SELF'];
    if($this->openPage<=0) {
    $next = 2;
    }

    else {
    $next = $this->openPage+1;
    }
    $prev = $this->openPage-1;
    $last = $this->pages;

    if($this->openPage > 1) {
    echo "<a href=$self/1>First</a>&nbsp";
    echo "<a href=$self/$prev>Prev</a>&nbsp";
    }
    else {
    echo "First&nbsp";
    echo "Prev&nbsp";
    }
    for($i=1;$i<=$this->pages;$i++) {
    if($i == $this->openPage)
    echo "$i&nbsp";
    else
    echo "<a href=$self/$i>$i</a>&nbsp";
    }
    if($this->openPage < $this->pages) {
    echo "<a href=$self/$next>Next</a>&nbsp";
    echo "<a href=$self/$last>Last</a>&nbsp";
    }
    else {
    echo "Next&nbsp";
    echo "Last&nbsp";
    }
    }
    }
    ?>

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    a posto, ho risolto e senza usare htaccess

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.