Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Created May 6, 2014 14:53
Show Gist options
  • Save ruliarmando/88f8ad93d114a2159418 to your computer and use it in GitHub Desktop.
Save ruliarmando/88f8ad93d114a2159418 to your computer and use it in GitHub Desktop.
kelas Paging
<?php
class Paging
{
private $conn;
private $table;
public $limit = 10;
public $offset = 0;
public $total = 0;
public $total_page = 0;
public $current_page = 0;
public function __construct($conn, $table, $curr_page, $limit = 20)
{
$this->conn = $conn;
$this->table = $table;
$this->current_page = $curr_page;
$this->limit = $limit;
$this->offset = $this->limit * (intval($this->current_page) - 1);
}
public function get_result($where = null)
{
$sql_query = "select * from {$this->table} ";
$this->total = $this->conn->num_rows(trim($sql_query));
if($where !== null){
$sql_query .= trim($where);
}
$sql_query .= " limit {$this->limit} offset {$this->offset}";
$result = $this->conn->all($sql_query);
$this->total_page = ceil($this->total / $this->limit);
return $result;
}
public function generate_link()
{
echo '<ul style="list-style-type:none;">';
for($i = 1; $i <= $this->total_page; $i++){
echo '<li style="float:left;margin-left:5px;"><a href="index.php?page='.$i.'">'.$i.'</a></li>';
}
echo '</ul>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment