hasil pencarian dengan paging

adit78 · Oct 29, 2012
mohon bantuannya suhu,supaya hasil pencarian yang dihasilkan sesuai dengan saat kita mengklik halaman selanjutnya
scriptnya:
<?php require_once('koneksi/koneksi.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php include ('header.php') ?>
<div id="isi">
  <div align="center"></div>
  <fieldset style="width:270px">
  <legend><b>Form Pencarian</b></legend>
  <form action="show_siswa.php?page=1" method="POST">
  <table>
  <tr>
  <td width="90"><input type="radio" name="field" value="no_induk" />No Induk </td>
  <td><input type="radio" name="field" value="nm_siswa" checked="checked" />Nama </td>
  </tr>
  <tr>
  <td colspan="2"><input type="text" name="value" />  <input type="submit" value="cari" /> </td>
  </tr>
  </table>
  </form>
  </fieldset>
  <form action="show_siswa.php?page=1" method="post">
  <input type="submit" value="reset" />
  </form>
<center>
  <h1>DATA SISWA</h1>
</center>
  <a href="input_siswa.php">+Tambah</a>
  <table border="1" cellpadding="3" cellspacing="0"><th>No</th><th>No Induk</a></th><th>Nama</a></th><th>Tempat</th><th>Tanggal Lahir</th><th>Jenis Kelamin</th><th>Pendidikan</th><th>Alamat</th><th>No telepon</th><th>Hasil Seleksi</th><th>Aksi</th>
  <?php 
  error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  //menampung variabel dari parsing
  $field=$_POST['field'];
  $value=$_POST['value'];
  //jika kosong,maka
  if(empty($field))
  {
  $cari=" ";
  }
  else
  {
  $cari=" WHERE $field LIKE '$value%'";
  }
  $warna1= "FFFFFF";
  $warna2= "#FFF8DC";
  $warna= $warna1;
  //jumlah data yg akan ditampilkan
  $dataperpage=5;
  if($_GET['page'])
  {
  $nopage=$_GET['page'];
  }
  else $nopage=1;
  // perhitungan offset
  $offset=($nopage-1)*$dataperpage;
  //query SQL untuk menampilkan data perhalaman sesuai offset
  $query = "SELECT * FROM tsiswa $cari order by nm_siswa LIMIT $offset, $dataperpage";
  $result= mysql_query($query) or die ('Error');
  // membaca nomer halaman
  $nopage=$_GET['page'];
  // membuat nomer urut awal disetiap halaman berdasarkan formula diatas
  $i=$nopage + ($nopage - 1) * ($dataperpage-1);
// menampilkan data
  while($data=mysql_fetch_array($result))
  {
  //background berwarna
  if($warna==$warna1){
  $warna=$warna2;}
  else {$warna=$warna1;}
  //memecah tanggal lahir
  $tanggal=explode('-',$data['tgl_lhr']);
  $tgl_lhr="$tanggal[2]-$tanggal[1]-$tanggal[0]";
  ?>
  <tr bgcolor=<?Php echo "$warna" ?> class='data'>
  <td><?php echo "$i" ?></td><?php $i++; ?>
  <td><?php echo "$data[no_induk]" ?></td>
  <td><?php echo "$data[nm_siswa]" ?></td>
  <td><?php echo "$data[tmpt_lhr]" ?></td>
  <td><?php echo "$tgl_lhr" ?></td>
  <td><?php echo "$data[jenkel]" ?></td>
  <td><?php echo "$data[pnddkn]" ?></td>
  <td><?php echo "$data[alamat]" ?></td>
  <td><?php echo "$data[no_telp]" ?></td>
  <td><?php echo "$data[hsl_slksi]" ?></td>
  <td><a href='input_siswa.php'>Tambah</a> | <a href='edit_siswa.php?no_induk=<?php echo "$data[no_induk]"; ?>'>Ubah</a> |<a href='delete_siswa.php?no_induk=<?php echo "$data[no_induk]"; ?>'> Hapus</a></td>
  </tr>
  <?php 
  }
  ?>
  </table>
  <p>
  <?php
  
  // mencari jumlah semua data dalam tabel siswa
  $query = "SELECT COUNT(*) AS jumdata FROM tsiswa .$cari";
  $hasil = mysql_query($query);
  $data = mysql_fetch_array($hasil);
  $jumdata=$data['jumdata'];
  
  // menentukan jumlah halaman yang muncul berdasarkan jumlah semua data
  $jumpage = ceil($jumdata/$dataperpage);
  // menampilkan link previous
  if ($nopage > 1) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($nopage-1).$cari."'>&lt;&lt; sebelumnya</a>";
  
  // memunculkan nomor halaman dan linknya
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 " <b>".$page."</b> ";
            else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page.$cari."'>".$page."</a> ";
            $showpage = $page;          
         }
}

// menampilkan link next

if ($nopage < $jumpage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($nopage+1).$cari."'>Selanjutnya&gt;&gt;</a>";
  ?>
  </p>
  <p>&nbsp;</p>
</center></div>
  <?php include ('footer.php') ?>
</body>
</html>
Silahkan login untuk menjawab!
-4
Loading...
Ellyx Christian · Oct 30, 2012 · 0 Suka · 4 Tidak Suka
<?php require_once('koneksi/koneksi.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
 
<body>
<?php include ('header.php') ?>
<div id="isi">
  <div align="center"></div>
  <fieldset style="width:270px">
  <legend><b>Form Pencarian</b></legend>
  <form action="show_siswa.php?page=1" method="get">
  <table>
  <tr>
  <td width="90"><input type="radio" name="field" value="no_induk" />No Induk </td>
  <td><input type="radio" name="field" value="nm_siswa" checked="checked" />Nama </td>
  </tr>
  <tr>
  <td colspan="2"><input type="text" name="value" />  <input type="submit" value="cari" /> </td>
  </tr>
  </table>
  </form>
  </fieldset>
  <form action="show_siswa.php?page=1" method="post">
  <input type="submit" value="reset" />
  </form>
<center>
  <h1>DATA SISWA</h1>
</center>
  <a href="input_siswa.php">+Tambah</a>
  <table border="1" cellpadding="3" cellspacing="0"><th>No</th><th>No Induk</a></th><th>Nama</a></th><th>Tempat</th><th>Tanggal Lahir</th><th>Jenis Kelamin</th><th>Pendidikan</th><th>Alamat</th><th>No telepon</th><th>Hasil Seleksi</th><th>Aksi</th>
  <?php 
  error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
  //menampung variabel dari parsing
  $field=$_GET['field'];
  $value=$_GET['value'];
  //jika kosong,maka
  if(empty($field))
  {
  $cari=" ";
  }
  else
  {
  $cari=" WHERE $field LIKE '$value%'";
  }
  $warna1= "FFFFFF";
  $warna2= "#FFF8DC";
  $warna= $warna1;
  //jumlah data yg akan ditampilkan
  $dataperpage=5;
  if($_GET['page'])
  {
  $nopage=$_GET['page'];
  }
  else $nopage=1;
  // perhitungan offset
  $offset=($nopage-1)*$dataperpage;
  //query SQL untuk menampilkan data perhalaman sesuai offset
  $query = "SELECT * FROM tsiswa $cari order by nm_siswa LIMIT $offset, $dataperpage";
  $result= mysql_query($query) or die ('Error');
  // membaca nomer halaman
  $nopage=$_GET['page'];
  // membuat nomer urut awal disetiap halaman berdasarkan formula diatas
  $i=$nopage + ($nopage - 1) * ($dataperpage-1);
// menampilkan data
  while($data=mysql_fetch_array($result))
  {
  //background berwarna
  if($warna==$warna1){
  $warna=$warna2;}
  else {$warna=$warna1;}
  //memecah tanggal lahir
  $tanggal=explode('-',$data['tgl_lhr']);
  $tgl_lhr="$tanggal[2]-$tanggal[1]-$tanggal[0]";
  ?>
  <tr bgcolor=<?Php echo "$warna" ?> class='data'>
  <td><?php echo "$i" ?></td><?php $i++; ?>
  <td><?php echo "$data[no_induk]" ?></td>
  <td><?php echo "$data[nm_siswa]" ?></td>
  <td><?php echo "$data[tmpt_lhr]" ?></td>
  <td><?php echo "$tgl_lhr" ?></td>
  <td><?php echo "$data[jenkel]" ?></td>
  <td><?php echo "$data[pnddkn]" ?></td>
  <td><?php echo "$data[alamat]" ?></td>
  <td><?php echo "$data[no_telp]" ?></td>
  <td><?php echo "$data[hsl_slksi]" ?></td>
  <td><a href='input_siswa.php'>Tambah</a> | <a href='edit_siswa.php?no_induk=<?php echo "$data[no_induk]"; ?>'>Ubah</a> |<a href='delete_siswa.php?no_induk=<?php echo "$data[no_induk]"; ?>'> Hapus</a></td>
  </tr>
  <?php 
  }
  ?>
  </table>
  <p>
  <?php
  // mencari jumlah semua data dalam tabel siswa
  $query = "SELECT COUNT(*) AS jumdata FROM tsiswa .$cari";
  $hasil = mysql_query($query);
  $data = mysql_fetch_array($hasil);
  $jumdata=$data['jumdata'];
 
  // menentukan jumlah halaman yang muncul berdasarkan jumlah semua data
  $jumpage = ceil($jumdata/$dataperpage);
  // menampilkan link previous
  if ($nopage > 1) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($nopage-1)."&field=".$_GET['field']."&value=".$_GET['value']."'>&lt;&lt; sebelumnya</a>";
 
  // memunculkan nomor halaman dan linknya
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 " <b>".$page."</b> ";
            else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."&field=".$_GET['field']."&value=".$_GET['value']."'>".$page."</a> ";
            $showpage = $page;          
         }
}
 
// menampilkan link next
 
if ($nopage < $jumpage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($nopage+1)."&field=".$_GET['field']."&value=".$_GET['value']."'>Selanjutnya&gt;&gt;</a>";
  ?>
  </p>
  <p>&nbsp;</p>
</center></div>
  <?php include ('footer.php') ?>
</body>
</html>
-4
Loading...
Ellyx Christian · Oct 30, 2012 · 0 Suka · 4 Tidak Suka
intinya adalah pada saat membuat search dan ingin ada pagination form yang digunakan harus menggunakan method get