<link href="gradient.css" rel="stylesheet" type="text/css">
<?php
//mysql_connect("localhost","root","");
//mysql_select_db("pintar");
include "includes/koneksi.php";

//echo "<table align=center><tr><th>No</th><th>Nama</th><th>Alamat</th></tr>";


// Langkah 1: Tentukan batas,cek halaman & posisi data
$batas   = 3;
$halaman = $_GET['halaman'];
if(empty($halaman)){
	$posisi  = 0;
	$halaman = 1;
}
else{
	$posisi = ($halaman-1) * $batas;
}

//Langkah 2: Sesuaikan perintah SQL
echo "<table>";

  $tampil = "select * from produk order by id_produk desc LIMIT $posisi,$batas";
  $hasil  = mysql_query($tampil);
  $sql=mysql_query("select * from produk order by id_produk desc LIMIT $posisi,$batas");
  $no = $posisi+1;
  
  while ($r=mysql_fetch_array($sql)){
    $harga     = number_format($r['harga'],0,",",".");
    $deskripsi = nl2br($r['deskripsi']); // membuat paragraf 
    $isi       = substr($deskripsi,0,220); // ambil sebanyak 220 karakter
    $isi       = substr($deskripsi,0,strrpos($isi," ")); // potong per spasi kalimat

	$no++;
    echo "<tr><td><img src='foto_produk/small_$r[gambar]' align=left hspace=20 border=0></td><td><b>$r[nama_produk]</b> <br /><br />
          $isi ... <a href=#>Selengkapnya</a></td></tr>
          <tr><td>Rp. <b>$harga</b> </td><td><a href=aksi.php?module=keranjang&act=tambah&id=$r[id_produk]><img src='images/beli.jpg' border=0></a></td></tr>
          <tr><td colspan=2><hr /></td></tr>";
  }
echo "</table>";

/*
$tampil = "SELECT * FROM anggota LIMIT $posisi,$batas";
$hasil  = mysql_query($tampil);

$no = $posisi+1;
while($r=mysql_fetch_array($hasil)){
  echo "<tr><td>$no</td><td>$r[nama]</td><td>$r[alamat]</td></tr>";
  $no++;
}
echo "</table><br>";
*/

//Langkah 3: Hitung total data dan halaman 
$tampil2 = mysql_query("SELECT * FROM produk ORDER BY id_produk desc");
$jmldata = mysql_num_rows($tampil2);
$jmlhal  = ceil($jmldata/$batas);


echo "<div class=paging>";
// Link ke halaman sebelumnya (previous)
if($halaman > 1){
	$prev=$halaman-1;
	echo "<span class=prevnext><a href=$_SERVER[PHP_SELF]?halaman=$prev>« Prev</a></span> ";
}
else{ 
	echo "<span class=disabled>« Prev</span> ";
}

// Tampilkan link halaman 1,2,3 ...
for($i=1;$i<=$jmlhal;$i++)
if ($i != $halaman){
	echo " <a href=$_SERVER[PHP_SELF]?halaman=$i>$i</a> ";
}
else{
	echo " <span class=current>$i</span> ";
}

// Link kehalaman berikutnya (Next)
if($halaman < $jmlhal){
	$next=$halaman+1;
	echo "<span class=prevnext><a href=$_SERVER[PHP_SELF]?halaman=$next>Next »</a></span>";
}
else{ 
	echo "<span class=disabled>Next »</span>";
}
echo "</div>";
echo "<p align=center>Total anggota : <b>$jmldata</b> orang</p>";
?>

Notice: Undefined index: halaman in C:\xampp\htdocs\php_template2\tampil_produk.php on line 12

line 12: $halaman = $_GET;

How to define halaman ? (translate: page) this coding is for paging.

if(!isset($_GET['halaman'])) {
$_GET['halaman'] = 1; // add default page number
}

$halaman = isset($_GET['halaman']) ? $_GET['halaman'] : 0;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.