", $number="%%number%%",$url) { $baris=10; $this->next=$next; $this->prev=$prev; $this->number=$number; $this->p["baris"]=$baris; $this->p["langkah"]=$langkah; //$_SERVER["REQUEST_URI"]=preg_replace("/page/[0-9]*/","",$_SERVER["REQUEST_URI"]); if (empty($_GET["page"])) { $this->page=1; } else { $this->page=$_GET["page"]; } } function db($host,$username,$password,$dbname) { $this->koneksi=mysql_pconnect($host, $username, $password) or die("Connection Error"); mysql_select_db($dbname); return $this->koneksi; } function query($query) { $kondisi=false; // only select if (!preg_match("/^[\s]*select*/i",$query)) { $query="select ".$query; } $querytemp = mysql_query($query); $this->p["count"]= mysql_num_rows($querytemp); // total page $this->p["total_page"]=ceil($this->p["count"]/$this->p["baris"]); // filter page if ($this->page<=1) $this->page=1; elseif ($this->page>$this->p["total_page"]) $this->page=$this->p["total_page"]; // awal data yang diambil $this->p["mulai"]=$this->page*$this->p["baris"]-$this->p["baris"]; $query=$query." limit ".$this->p["mulai"].",".$this->p["baris"]; $query=mysql_query($query) or die(mysql_error()); $this->query=$query; } function result() { return $result=mysql_fetch_object($this->query); } function result_assoc() { return mysql_fetch_assoc($this->query); } function print_no() { $number=$this->p["mulai"]+=1; return $number; } function print_info() { $page=array(); $page["start"]=$this->p["mulai"]+1; $page["end"]=$this->p["mulai"]+$this->p["baris"]; $page["total"]=$this->p["count"]; $page["total_pages"]=$this->p["total_page"]; if ($page["end"] > $page["total"]) { $page["end"]=$page["total"]; } if (empty($this->p["count"])) { $page["start"]=0; } return $page; } function print_link($url) { $url = preg_replace('/ /', '+', $url); //generate template function number($i,$number) { return ereg_replace("^(.*)%%number%%(.*)$","\\1$i\\2",$number); } $print_link = false; if ($this->p["count"]>$this->p["baris"]) { // print prev if ($this->page>1) $print_link .= ''.$this->prev.''; // set number $this->p["bawah"]=$this->page-$this->p["langkah"]; if ($this->p["bawah"]<1) $this->p["bawah"]=1; $this->p["atas"]=$this->page+$this->p["langkah"]; if ($this->p["atas"]>$this->p["total_page"]) $this->p["atas"]=$this->p["total_page"]; // print start if ($this->page<>1) { for ($i=$this->p["bawah"];$i<=$this->page-1;$i++) $print_link .=''.number($i,$this->number).''; } // print active if ($this->p["total_page"]>1) $print_link .= ''.number($this->page,$this->number).''; // print end for ($i=$this->page+1;$i<=$this->p["atas"];$i++) $print_link .= ''.number($i,$this->number).''; // print next if ($this->page<$this->p["total_page"]) $print_link .= 'Next »'.$this->next.''; return $print_link; } } } ?>