Ini adalah tutorial membuat pagination sederhana menggunakan php dan css. Metode pengiriman variabelnya menggunakan $_GET sehingga mudah disesuaikan dengan fungsi php yang telah anda buat.

1. File CSS
/*pagination*/
#tnt_pagination {
margin-top:10px;
display:block;
text-align:left;
height:22px;
line-height:21px;
clear:both;
padding-top:3px;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
font-weight:normal;
}

#tnt_pagination a:link, #tnt_pagination a:visited{
padding:7px;
padding-top:2px;
padding-bottom:2px;
border:1px solid #ddd;
margin-left:5px;
text-decoration:none;
background-color:#eee;
color:#666;
width:22px;
font-weight:normal;
}

#tnt_pagination a:hover {
background-color:#EF652A;
border:1px solid #F30;
color:#fff;
}

#tnt_pagination .active_tnt_link {
padding:7px;
padding-top:2px;
padding-bottom:2px;
margin-left:5px;
text-decoration:none;
color:#fff;
cursor:default;
background-color:#EF652A;
border:1px solid #F30;}

#tnt_pagination .disabled_tnt_pagination {
padding:7px;
padding-top:2px;
padding-bottom:2px;
border:1px solid #EBEBEB;
margin-left:5px;
text-decoration:none;
background-color:#F5F5F5;
color:#D7D7D7;
cursor:default;
}
/* — end pagination—*/
2. File PHP

<?php

echo ‘<div id=”tnt_pagination”>’;

$host = $_SERVER[‘HTTP_HOST’];
$self = $_SERVER[‘PHP_SELF’];
$query = !empty($_SERVER[‘QUERY_STRING’]) ? $_SERVER[‘QUERY_STRING’] : null;
$url = !empty($query) ? “http://$host$self?$query” : “http://$host$self”;
$url=str_replace(‘index.php’,”,$url);

$qpagination=”SELECT COUNT(id) AS jumData FROM produk”;
$rdata=mysql_fetch_array(mysql_query($qpagination));
$jumData = $rdata[jumData];

if($jumData > $dataPerPage){
$jumPage = ceil($jumData/$dataPerPage);
if ($noPage > 1) echo “<a href=’$url&nav=”.($noPage-1).”‘>&lt;&lt; Prev</a>”;
for($page = 1; $page <= $jumPage; $page++){
if ((($page >= $noPage – 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage)){
if (($showPage == 1) && ($page != 2)) echo “…”;
if (($showPage != ($jumPage – 1)) && ($page == $jumPage)) echo “…”;
if ($page == $noPage) echo ” <span class=’active_tnt_link’>”.$page.”</span> “; else echo ” <a href=’$url&nav=”.$page.”‘>”.$page.”</a> “;
$showPage = $page;
}
}
if ($noPage < $jumPage) echo “<a href=’$url&nav=”.($noPage+1).”‘>Next &gt;&gt;</a>”;
}

echo'</div>’;
?>

(Visited 981 times, 1 visits today)