分页

时间:2017-04-03 05:45:36

标签: php mysql ajax

我的原始链接的加载页2,3,4等有问题错误http://bali-webdesign.com/staging/astina3/subkategori-Bali%20Package-3-3.htm ..

这是我的class_paging.php

class Paging{
function cariPosisi($batas){
    if(empty($_GET['halaman'])){
        $posisi=0;
        $_GET['halaman']=1;
    }
    else{
        $posisi = ($_GET['halaman']-1) * $batas;
    }
    return $posisi;
}
function jumlahHalaman($jmldata, $batas){
    $jmlhalaman = ceil($jmldata/$batas);
    return $jmlhalaman;
}
function navHalaman($halaman_aktif, $jmlhalaman){
    $link_halaman = "";
    // Link ke halaman pertama (first) dan sebelumnya (prev)
    if($halaman_aktif > 1){
        $prev = $halaman_aktif-1;
        $link_halaman .= "<li class='paginate_button previous' id='table-gallery_previous'><a aria-controls='table-gallery' data-dt-idx='0' tabindex='0' href=$_SERVER[PHP_SELF]?halaman=1>&laquo;</a></li>
        <li><a href=$_SERVER[PHP_SELF]?halaman=$prev>&lsaquo;</a></li>";
    }
    else{ 
        $link_halaman .= "<li class='disabled'><a>&laquo;</a></li><li class='disabled'><a>&lsaquo;</a></li>";
    }
    // Link halaman 1,2,3, ...
    $angka = ($halaman_aktif > 3 ? "" : " "); 
    for ($i=$halaman_aktif-2; $i<$halaman_aktif; $i++){
        if ($i < 1)
        continue;
        $angka .= "<li><a href=$_SERVER[PHP_SELF]?halaman=$i>$i</a></li>";
    }
    $angka .= "<li class='paginate_button active'><a aria-controls='table-gallery' data-dt-idx='1' tabindex='0'>$halaman_aktif</a></li>";
    for($i=$halaman_aktif+1; $i<($halaman_aktif+3); $i++){
        if($i > $jmlhalaman)
        break;
        $angka .= "<li><a aria-controls='table-gallery' data-dt-idx='1' tabindex='0' href=$_SERVER[PHP_SELF]?halaman=$i>$i</a></li>";
    }
    $angka .= ($halaman_aktif+2<$jmlhalaman ? "<li><a href=$_SERVER[PHP_SELF]?halaman=$jmlhalaman>$jmlhalaman</a></li>" : " ");
    $link_halaman .= "$angka";
    // Link ke halaman berikutnya (Next) dan terakhir (Last) 
    if($halaman_aktif < $jmlhalaman){
        $next = $halaman_aktif+1;
        $link_halaman .= "<li class='paginate_button next' id='table-gallery_next'><a aria-controls='table-gallery' data-dt-idx='2' tabindex='0' href=$_SERVER[PHP_SELF]?halaman=$next>&rsaquo;</a></li><li><a href=$_SERVER[PHP_SELF]?halaman=$jmlhalaman>&raquo;</a></li>";
    }
    else{
        $link_halaman .= "<li class='disabled'><a href='#'>&rsaquo;</a></li><li class='disabled'><a href='#'>&raquo;</a></li>";
    }
    return $link_halaman;
}
}

然后在我加载分页功能的页面中

include "inc/config/class_paging.php";
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
                    $s      = new Paging;
        $batas  = 10;
        $posisi = $s->cariPosisi($batas);
                    $produk = mysql_query("SELECT * FROM produk where id_subkategori='$_GET[idkk]' LIMIT $posisi,$batas");
                    $jmldata = mysql_num_rows(mysql_query("SELECT * FROM produk"));

                    while($p=mysql_fetch_array($produk)){
echo "blabla";
}
$jmlhalaman  = $s->jumlahHalaman($jmldata, $batas);
           $linkHalaman = $s->navHalaman($_GET[halaman], $jmlhalaman);

                    echo "<div align='center' class='dataTables_paginate paging_simple_numbers' id='table-about_paginate'>
            <ul class='pagination'>$linkHalaman</ul>
        </div>";

现在,当我点击分页的第2页按钮时,结果链接将是bali-webdesign.com/staging/astina3/subkategori.php?halaman=2但该链接无法显示我的数据。我想点击第2页的分页按钮时会显示我的数据

我应该在class_paging.php中为链接url更改什么,以便它可以在第2,3,4页等显示数据

0 个答案:

没有答案