| ini script nya : <?php
function buat_paging($curPage,$totalRec,$maxRec){ $totalPage; $totalPage=ceil($totalRec/$maxRec); $str="";
/*--------------------------Tombol Prev-----------------------*/
if($curPage>1){ $prevPage = $curPage-1; $str.=" ".makeLink("prev","?p=".$prevPage)." "; }
/*-------------------------Untuk Page Number----------------*/
for($i=1;$i<=$totalPage;$i++){ if($i==$curPage){ $bold=true; }else{ $bold=false; } $str.=" ".makeLink($i,"?p=".$i,$bold)." "; }
/*--------------------------Tombol Next-----------------------*/
if($curPage<$totalPage){ $nextPage=$curPage+1; $str.=" ".makeLink("next","?p=".$nextPage)." "; }
return $str;
} function makeLink($str,$url,$bold="false"){ if($bold){ $str="<b>".$str."</b>"; } return '<a href="'.$url.'">'.$str.'</a>'; }
//connection $con = mysql_connect("localhost","root",""); mysql_select_db("paging",$con); $total=mysql_query("select * from berita",$con); $total=mysql_num_rows($total); $total=ceil($total/4); $curPage=abs((int)$_GET['p']); if ($curPage==null){$curPage=1;} elseif($curPage>$total){$curPage=$total;} $maxRec=4;
$startRec = ($curPage-1)*$maxRec; $sql = "select * from berita limit ".$startRec.",".$maxRec; $rs=mysql_query($sql,$con); while ($row = mysql_fetch_array($rs)) { echo "Ini adalah : ".$row['artikel']."<br />"; } $total_record=mysql_query("select * from berita",$con); $total_record=mysql_num_rows($total_record);
echo "<br>";
echo buat_paging($curPage,$total_record,$maxRec);
?> |