Quoting catur <[EMAIL PROTECTED]>:

> Salam hormat & sejahtera selalu...
> 
> 
> Bagaimana caranya menampilkan hal dlm web agar data tampil 100
> rec/halaman web, trus ada button Next - Prev. Saya sudah cuba dng limit
> tapi blon berhasil u/hal ke 2.
> Saya menggunakan script antara lain ...
> 
> if action == lanjut 
>  {
>   ini scriptnya
>  }
> 
> if action == lalu
>  {
>   ini scriptnya
>  }
> 
> form action="xxx.php" method="post">
> <input type="Hidden" name="action" value="lanjut">
> <input type="Hidden" name="action" value="lalu">
> <input type="submit" name="submit" value="Next">
> <input type="submit" name="submit" value="Prev">
> </form>
> 

Source-code-nya ada di bawah. Maaf masih kuran dokumentasinya.
Lisensinya GPL ajah :D
Contoh pemakaiannya:
----------------------------------------------------------------------
<?
include('paging.class.php');

$page = $_GET['page'];
$this_page = $_SERVER['PHP_SELF'];

$jumlah_nav = 7;
$jumlah_item = 3000;
$jumlah_item_per_page = 100;

$nav = new paging($page, 7,
                  $jumlah_item_per_page, $jumlah_item,
                  "$this_page?page=", "&nbsp;|&nbsp;",
                  "&lt;&lt;", "Prev",
                  "Halaman ",
                  "Next", "&gt;&gt;",
                  "<h3 style=\"display:inline;\">", "</h3>",
                  "<b>", "</b>",
                  "2.1");

$nav->showNavigasi();

?>
<p>
<div>
<?for($i=($nav->start + 1);
      $i<=($nav->start + $jumlah_item_per_page);
      $i++) {
?>
<?=$i?><br/>
<?}?>
</div>
</p>
----------------------------------------------------------------------

File paging.class.php:
----------------------------------------------------------------------
<?
/*
 * Class paging
 * Menyediakan fungsi untuk membuat navigasi halaman yang ada
 */
class paging {
    var $cur_page;
    var $max_page;
    var $item_per_page;
    var $num_item;
    var $URL;
    var $separator;
    var $version;
    var $first;
    var $pref;
    var $title;
    var $next;
    var $last;
    var $open_tag;
    var $close_tag;
    var $open_active_tag;
    var $close_active_tag;
    var $start;
    var $num_page;
    var $page_array;
    var $show_first;
    var $show_prev;
    var $show_next;
    var $show_last;

    function paging($cur_page, $max_page,
                    $item_per_page, $num_item,
                    $URL, $separator="&nbsp;",
                    $first="&lt;&lt;", $pref="&lt;",
                    $title=NULL,
                    $next="&gt;", $last="&gt;&gt;",
                    $open_tag="", $close_tag="",
                    $open_active_tag="<b>", $close_active_tag="</b>",
                    $version="2.1") {
        $this->cur_page = $cur_page;
        $this->max_page = $max_page;
        $this->item_per_page = $item_per_page;
        $this->num_item = $num_item;
        $this->URL = $URL;
        $this->separator = $separator;
        $this->first = $first;
        $this->pref = $pref;
        $this->title = $title;
        $this->next = $next;
        $this->last = $last;
        $this->open_tag = $open_tag;
        $this->close_tag = $close_tag;
        $this->open_active_tag = $open_active_tag;
        $this->close_active_tag = $close_active_tag;
        $this->version = $version;

        $this->num_page = ceil($this->num_item / 
                               $this->item_per_page);
        if(($this->num_page > 0) &&
           ($this->cur_page > $this->num_page)) {
                $this->cur_page = $this->num_page;
        }
        $this->start = ($this->cur_page - 1) * $this->item_per_page;
        $this->page_array = 
            $this->createNavigasi($this->cur_page,
                                  $this->num_page,
                                  $this->max_page);

        if($this->version=="1.0") {
            $this->show_first = true;
            $this->show_prev = true;
            $this->show_next = true;
            $this->show_last = true;
        } else if($this->version=="2.0") {
            $this->show_first = false;
            $this->show_prev = true;
            $this->show_next = true;
            $this->show_last = false;
        } else if($this->version=="2.1") {
            $this->show_first = false;
            $this->show_prev = false;
            $this->show_next = false;
            $this->show_last = false;
        } else {
            $this->show_first = true;
            $this->show_prev = true;
            $this->show_next = true;
            $this->show_last = true;
        }
    }

    // Fungsi untuk menghasilkan array halaman yang akan tampil
    function createNavigasi($cur_page, $num_page, $max_page) {
        if($num_page > $max_page) {
            $half = floor($max_page / 2);
            $start = $cur_page - $half;
            $end = $cur_page + $half;
            // penentuan $start dan $end
            if($start < 1) {
                $start = 1;
                $end = $start + $max_page - 1;
            } else if($end > $num_page) {
                $end = $num_page;
                $start = $end - $max_page + 1;
            } else {
                $end = $start + $max_page - 1;
            }
            //beginning
            if($start == 2) {
                $hasil[] = 1;
            } else if($start > 2) {
                $hasil[] = 1;
                $hasil[] = "...";
            }
            // main loop
            for($i=$start; $i<=$end; $i++) {
                $hasil[] = $i;
            }
            // end
            if($end == ($num_page - 1)) {
                $hasil[] = $num_page;
            } else if($end < ($num_page - 1)) {
                $hasil[] = "...";
                $hasil[] = $num_page;
            }
        } else {
            // normal loop
            for($i=1; $i<=$num_page; $i++) {
                $hasil[] = $i;
            }
        }
        return $hasil;
    }

    // Fungsi untuk menampilkan isi array
    function showNavigasi() {
        if($this->cur_page > 1) {
            if($this->show_first) {
                echo("{$this->open_tag}".
                     "<a href=\"{$this->URL}1\">".
                     "$this->first</a>".
                     "{$this->separator}{$this->close_tag}");
            }
            echo("{$this->open_tag}".
                 "<a href=\"$this->URL".($this->cur_page - 1)."\">".
                 "$this->pref</a>".
                 "{$this->separator}{$this->close_tag}");
        } else {
            if($this->show_first) {
                echo("{$this->open_tag}".
                     "{$this->open_active_tag}".
                     "$this->first{$this->close_active_tag}".
                     "{$this->separator}{$this->close_tag}");
            }
            if($this->show_prev) {
                echo("{$this->open_tag}".
                     "{$this->open_active_tag}".
                     "$this->pref{$this->close_active_tag}".
                     "{$this->separator}{$this->close_tag}");
            }
        }
        foreach($this->page_array as $hal) {
            if($hal == "...") {
                echo("{$this->open_tag}".
                     "$hal".
                     "{$this->separator}{$this->close_tag}");
            } else if($hal == $this->cur_page) {
                echo("{$this->open_tag}".
                     "{$this->open_active_tag}".
                     "{$this->title}$hal{$this->close_active_tag}".
                     "{$this->separator}{$this->close_tag}");
            } else {
                echo("{$this->open_tag}".
                "<a href=\"{$this->URL}$hal\">".
                "{$this->title}$hal</a>".
                "{$this->separator}{$this->close_tag}");
            }
        }
        if($this->cur_page < $this->num_page) {
            echo("{$this->open_tag}".
                 "<a href=\"{$this->URL}".
                 ($this->cur_page + 1)."\">$this->next</a>".
                 "{$this->separator}{$this->close_tag}");
            if($this->show_last) {
                echo("{$this->open_tag}".
                     "<a href=\"{$this->URL}{$this->num_page}\">".
                     "$this->last</a>{$this->close_tag}");
            }
        } else {
            if($this->show_next) {
                echo("{$this->open_tag}".
                     "{$this->open_active_tag}".
                     "$this->next{$this->close_active_tag}".
                     "{$this->separator}{$this->close_tag}");
            }
            if($this->show_last) {
                echo("{$this->open_tag}".
                     "{$this->open_active_tag}".
                     "$this->last{$this->close_active_tag}".
                     "{$this->close_tag}");
            }
        }
    }
}
?>
----------------------------------------------------------------------

-- 
Donny Kurnia  --  13500021
Information System Laboratory
Department of Informatics
Bandung Institute of Technology

--
Berhenti langganan: [EMAIL PROTECTED]
Arsip dan info: http://linux.or.id/milis.php

Kirim email ke