Minggu, 11 September 2016

Syntax Php utk membuat Image Gallery

Di bawah ini ada script untuk menampilkan image gallery dalam bentuk paging (seperti tampilan search google dalam hal 1,2,3, dst).............semoga bisa membantu...........

<?
$dbhost="localhost";
$dbUSER="";
$dbPASS="";
$DBname="test";

$CONNECTION=mysql_connect($dbhost,$dbUSER,$dbPASS) or die ("CONNECTION ERROR!");
mysql_select_db($DBname,$CONNECTION) or DIE ("Unable to select database");
echo "sukses koneksi";
?>

<?
$jumlahitem=5;
$baris=0;
$namafile="paging.php";
$judul=array("id produk","nama produk","qty");
if(empty($_GET['nohal']))
{
if($baris == 0)
{
$nohal= $baris + 1;
}
}
else
{
$nohal=$_GET['nohal'];
$baris=($nohal - 1)* $jumlahitem;
}

if($nohal % $jumlahitem == 0)
{
$counterawal = $nohal -($jumlahitem - 1);
}
else
{
$counterawal = $nohal - ($nohal % $jumlahitem) + 1;
}

$counterakhir = $counterawal + ($jumlahitem - 1);
?>

<?
$query= "SELECT ID_Produk,Nama_Produk,Qty FROM tproduk";
$trecord = mysql_query($query);
$result = mysql_query($query ." LIMIT $baris, $jumlahitem ");
$jmlrecord = mysql_num_rows($trecord);
$maxhal = $jmlrecord % $jumlahitem;
if($jmlrecord % $jumlahitem==0)
{
$maxhal = $jmlrecord/$jumlahitem;
}
else
{
$maxhal = ceil($jmlrecord/$jumlahitem);
}
?>

<html>
<body>
<table border=1>
<tr>
<?
foreach ($judul as $i => $value)
{
print "<th>$judul[$i]</th>";
}
?>
</tr>
<?PHP
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
?>
<tr valign=top>
<?
foreach ($judul as $i => $value)
{
print "<td>$row[$i]</td>";
}
?>
</tr>
<?php
}
?>
</table>
<table>
<tr>
<td>
<div align="center">
<?php
print "[";
$c=0;
for($c=$counterawal;$c<=$counterakhir;$c++)
{
if($c<$maxhal)
{
if($c==$nohal)
{
if($c % $jumlahitem==0)
{
print "$c";
}
else
{
print "$c, ";
}
}
elseif($c % $jumlahitem==0)
{
echo "<a href=$namafile?nohal=$c>$c</a>";
}
else
{
echo "<a href=$namafile?nohal=$c>$c</a>, ";
}
}
else
{
if($nohal==$maxhal)
{
print "$c";
break;
}
else
{
echo "<a href=$namafile?nohal=$c>$c</a>";
break;
}
}
}
echo "]";
?>
</div>
</td>
</tr>
</table>
<?
mysql_free_result($result);
mysql_free_result($trecord);
?>
</body>
</html>

0 komentar:

Posting Komentar