I have a query by different attributes. When one query is started and we are for example on page 7, and a new attribute is chosen, the query still shows the 7 page of new results. And it should show page 1 as the new attribute is chosen. Could you help me with that?
<?php
class Pagination
{
public $current_page;
public $per_page;
public $total_count;
public $links_on_page = 10;
public $page_links = 15;
public $current_page_string = '';
public function __construct($page=1, $per_page=10, $total_count=0){
$this->current_page = ($page > 0) ? (int)$page : 1;
$this->per_page = abs((int)$per_page);
$this->total_count = abs((int)$total_count);
}
public function offset() {
return ($this->current_page - 1) * $this->per_page;
}
public function total_pages() {
return ceil($this->total_count/$this->per_page);
}
public function previous_page() {
return $this->current_page - 1;
}
public function next_page() {
return $this->current_page + 1;
}
public function has_previous_page() {
return $this->previous_page() >= 1 ? true : false;
}
public function has_next_page() {
return $this->next_page() <= $this->total_pages() ? true : false;
}
public function remaining_links($dim = 0){
return $this->page_links = $this->page_links - $dim;
}
public function render_pagination_bar($self = '', $addcond = '')
{
$cond='';
if($addcond)
{
foreach($addcond as $k=>$v)
{
$cond.="&pattr_{$k}=$v";
}
}
$return = '';
if($this->total_pages() > 1) {
if($this->has_previous_page())
{
$return .= a( href("$self&page=".$this->previous_page().$cond) , "« Poprzednia", null, 'link', null, null, null, true);
}
if($this->total_pages() > 10):
//print first
if($this->current_page > 6):
if($this->current_page == 1) {
$this->current_page_string = "{$self}&page=1";
$return .= span(1, null, 'selectedpage page_num');
} else {
$return .= a( href("{$self}&page=1{$cond}") , 1, null, 'page_num', null, null, null, true);
}
//append dots
if($this->current_page > 7)
$return .= " ... ";
endif;
//print current and 3 pages bck and 5 pages fwd
$startcondition = ($this->current_page > 5) ? ($this->current_page - 5) : 1;
$endcondition = ($this->current_page < ($this->total_pages() - 6)) ? ($this->current_page + 5) : $this->total_pages();
for($i = $startcondition; $i <= $endcondition; $i++) {
if($i == $this->current_page) {
$this->current_page_string = "{$self}&page={$i}{$cond}";
$return .= span($i, null, 'selectedpage page_num');
} else {
$return .= a( href("{$self}&page={$i}{$cond}") , $i, null, 'page_num', null, null, null, true);
}
}
//print last
if($this->current_page < ($this->total_pages() - 6)):
//append dots
$return .= " ... ";
if($this->current_page == $this->total_pages()) {
$this->current_page_string = "{$self}&page=".$this->total_pages();
$return .= span($this->total_pages(), null, 'selectedpage page_num');
} else {
$return .= a( href("{$self}&page=".$this->total_pages().$cond) , $this->total_pages(), null, 'page_num', null, null, null, true);
}
endif;
else:
for($i=1; $i <= $this->total_pages(); $i++) {
if($i == $this->current_page) {
$this->current_page_string = "{$self}&page={$i}{$cond}";
$return .= span($i, null, 'selectedpage page_num');
} else {
$return .= a( href("{$self}&page={$i}{$cond}") , $i, null, 'page_num', null, null, null, true);
}
}
endif;
if($this->has_next_page()) {
$return .= a( href("$self&page=".$this->next_page().$cond) , "» Następna", null, 'link', null, null, null, true);
}
}
return (!empty($return)) ? div($return, "pagination", "textcenter") : null;
}
}
?>