<?php
include "koneksiphp.php";
$dataperhalaman=3;
if(isset($_GET["halaman"])){
$nohalaman=$_GET["halaman"];
} else {
$nohalaman=1;
}
$offset=($nohalaman-1)*$dataperhalaman;
$query="SELECT * FROM mahasiswa ORDER BY nim
LIMIT $offset, $dataperhalaman";
$hasil=mysql_query($query) or die('error');
echo "<table border=1>";
echo
"<tr><td>NIM</td><td>NAMA</td><td>ALAMAT</td></tr>";
while($data=mysql_fetch_array($hasil)){
echo
"<tr><td>$data[nim]</td><td>$data[nama]</td><td>$data[alamat]</td></tr>";
}
echo "</table>";
$query="SELECT COUNT(*) AS jumlahdata FROM
mahasiswa";
$hasil=mysql_query($query);
$data=mysql_fetch_array($hasil);
$jumlahdata=$data["jumlahdata"];
$jumlahhalaman=ceil($jumlahdata/$dataperhalaman);
if($nohalaman>1){
echo
"<a href=$PHP_SELF?halaman=".($nohalaman-1)."> <<
Prev </a>";
}
for($halaman=1; $halaman <= $jumlahhalaman;
$halaman++){
if((($halaman
>= $nohalaman-3) && ($halaman <= $nohalaman+3)) || ($halaman==1)
|| ($halaman==$jumlahhalaman)){
if(($tampilhalaman==1)
&& ($halaman != 2)){
echo
"...";
}
if(($tampilhalaman
!= ($jumlahhalaman-1)) && ($halaman == $jumlahhalaman)){
echo
"...";
}
if($halaman
== $nohalaman){
echo
"$halaman";
}
else{
echo
"<a href=$PHP_SELF?halaman=$halaman> $halaman </a>";
}
$tampilhalaman=$halaman;
}
}
if($nohalaman < $jumlahhalaman){
echo
"<a href=$PHP_SELF?halaman=".($nohalaman+1)."> Next
>></a>";
}
?>
Skrip/Code PHP: Membuat Halaman
4/
5
Oleh
Unknown