PHP :: function membuat pagination sederhana dalam dengan php

perlu diketahui ya, setiap aku buat post coding biasanya dalam bentuk function, kalau yang masih bingung function tolong pelajari dahulu nanti malah puyeng bacannya ya, jangan asal copas copas aja, oke.. semoga bermanfaat

if (isset($_GET[‘page’]) && !empty($_GET[‘page’]))
{
$page = (int)$_GET[‘page’];
}
if (isset($_GET[‘perPage’]) && !empty($_GET[‘perPage’]))
{
$dataPerPage = (int)$_GET[‘perPage’];
}

function Pagination($pagedefault,$limit,$querypagination)
{
if (isset($_GET[‘Berdasarkan’]) && !empty($_GET[‘Berdasarkan’]) && isset($_GET[‘isi’]) && !empty($_GET[‘isi’]))
{
$berdasarkan = $_GET[‘Berdasarkan’];
$isi = $_GET[‘isi’];
$countTotalRow = mysql_query($querypagination);
}
else
{
$countTotalRow = mysql_query($querypagination);
}
$queryResult = mysql_fetch_assoc($countTotalRow);
$totalRow = $queryResult[‘total’];
$totalPage = ceil($totalRow / $limit);
$page = 1;
?>
<p>
<?php
if (isset($_GET[‘perPage’]) && !empty($_GET[‘perPage’]))
{
echo “Jumlah “.$totalRow.” Data, “;
}
else
{
echo “Jumlah “.$totalRow.” Data, “;
}
if (isset($_GET[‘page’]) && !empty($_GET[‘page’]))
{
echo “Halaman “.$_GET[‘page’].” Dari “.$totalPage.” Halaman”;
}
else
{
echo “Halaman “.$pagedefault.” Dari “.$totalPage.” Halaman”;
}
?>
</p>

<a href=”index.php?page=1&perPage=<?php echo $limit; ?>”>
<?php btn_pagination(‘« sebelumnya’); ?>
</a>
<?php
while ($page <= $totalPage)
{
?>
<a href=”?page=<?php echo $page; ?>&perPage=<?php echo $limit; ?>”>
<?php btn_pagination($page); ?>
</a>
<?php
if ($page < $totalPage)
echo ” “;
$page++;
}
?>
<a href=”index.php?page=<?php echo $totalPage; ?>&perPage=<?php echo $limit; ?>”>
<?php btn_pagination(‘berikutnya »’); ?>
</a>
<?php
}

Please follow and like us:
10

Leave a Reply

Your email address will not be published. Required fields are marked *