<! DOCTYPE HTML>
<html>
<head>
<title>DATABASE PEMUDA</title>
</head>
<body>
<form method = 'get' action = 'paging_203.php'>
Search nama <input type = 'text' name = 'nama' id = 'nama'> <input type = 'submit' name = 'oke' value = 'cari'>
</form>
<?php
if(isset($_GET['oke'])){
$connect = mysql_connect('localhost','root','');
mysql_select_db('pemuda',$connect);
//LANGKAH 1
$batas = 5;
$halaman = isset($_GET['halaman']) ? (int) $_GET['halaman'] : 1;
$halaman = max(1, $halaman); // menghindari halaman <= 0, misal -1
$posisi = ($halaman - 1) * $batas;
//LANGKAH 2
$nama = $_GET['nama'];
$sql = "SELECT * FROM pemudacephin WHERE nama LIKE '%$nama%' LIMIT $posisi, $batas";
$tampil = mysql_query($sql);
$jumlah = mysql_num_rows($tampil);
if($jumlah > 0){
printf("<table border = '1'>
<tr>
<td>No</td>
<td>No Id</td>
<td>Nama</td>
<td>No Rumah</td>
<td>TTL</td>
<td>No Hp</td>
<td>Kesibukan</td>
<td>Kelamin</td>
</tr>");
$no = $posisi + 1;
while($row = mysql_fetch_array($tampil)){
printf("<tr>
<td>$no</td>
<td>$row[no]</td>
<td>$row[nama]</td>
<td>$row[no_rumah]</td>
<td>$row[ttl]</td>
<td>$row[no_hp]</td>
<td>$row[kesibukan]</td>
<td>$row[kelamin]</td>
</tr>");
$no++;
}
printf("</table>");
//LANGKAH 3
$tampil2 = mysql_query("SELECT * FROM pemudacephin WHERE nama LIKE '%$nama%'");
$jmldata = mysql_num_rows($tampil2);
$jmlhalaman = ceil($jmldata/$batas);
$file = "paging_203.php";
printf("<br><b>HALAMAN : </b>");
for($i = 1; $i <= $jmlhalaman; $i++)
if($i != $halaman){
printf("<a href = $file?halaman=$i&nama=$nama>$i</a>");
}else{
printf("<b>$i</b>");
}
printf("<p>DITEMUKAN <b>$jmldata</b> ORANG DENGAN NAMA <b>$nama</b></p>");
}else{
printf("TIDAK DITEMUKAN ORANG DENGAN NAMA <b>$nama</b>");
}
}
printf("<a href = 'paging_1.php'>LIHAT SEMUA DATA</a>");
?>
</body>
</html>