semoga bermanfaat yah.
Ok Let's to do
sesuai dengan judul tulisannya, kali ini kita belajar bareng mengenai pembuatan Paging dengan coding PHP menggunakan teknik OOP atau Object Oriented Programming Syle.
Langsung aja cekidot
<?php
class Pagination{
function Paginate($values,$per_page){
$total_values = count($values);
if(isset($_GET['page'])){
$current_page = $_GET['page'];
}else{
$current_page = 1;
}
$counts = ceil($total_values / $per_page);
$param1 = ($current_page - 1) * $per_page;
$this->data = array_slice($values,$param1,$per_page);
for($x=1; $x<= $counts; $x++){
$numbers[] = $x;
}
return $numbers;
}
function fetchResult(){
$resultsValues = $this->data;
return $resultsValues;
}
}
// Sample Usage
$pag = new Pagination();
$data = array("Honda","Yamaha","Suzuki","Kawasaki","Bajaj");
$numbers = $pag->Paginate($data,3);
$result = $pag->fetchResult();
foreach($result as $r){
echo '<div>'.$r.'</div>';
}
foreach($numbers as $num){
echo '<a href="paging.php?page='.$num.'">'.$num.'</a>';
}
?>
0 comments:
Post a Comment