Welcome Guest, Not a member yet? Register   Sign In
Pagination jumping by per_page value?
#1

[eluser]papasnorkle[/eluser]
Hi, I'm trying to whip up some simple pagination for a gallery of photos, but I've come up against a bit of a brainblock. I'm newish to codeigniter and I really can't code all that well to begin with, so apologies for any nonsense that I output.

My pagination seems to work in the sense that if I physically type in the address
www.domain.com/home/page/ - I get the first 16 results
www.domain.com/home/page/1/ - I get the next 16 results
www.domain.com/home/page/2/ - I get the next 16 results and so on

However, when I click 'Next' in my pagination I get directed to
www.domain.com/home/page/16/ then
www.domain.com/home/page/32/ and so on

I believe the pagination is getting this number either from the per_page value, but that's just a guess. I'm completely out of my league.

I'm thinking that all I need to do is kindly ask the next button to point to the next page rather than page 16 and we'd be good, but I can't seem to work out why it's not complying with me.

Here's some code that I feel might be relevant to the issue, apologies if it seems disjointed, it's a work in progress.

Code:
function get_pagination_config($type,$extra1="",$extra2="")
{
  $config = array();
  $config['base_url'] = base_url().$type.'/page';
  $config['use_page_numbers'] = TRUE;
  $config['display_pages'] = FALSE;
  $config['next_link'] = ' Next >';
  $config['prev_link'] = '< Previous ';
  $config['last_link'] = FALSE;
  $config['first_link'] = FALSE;
  switch($type)
  {
   case 'home':
    $config['uri_segment'] = 3;
    $config['total_rows'] = $this->get_total_rows($rows);
    $config['per_page'] = 16;
   break;
  }
  return $config;
}

Code:
function get_photomagraphs($pid="", $pagenum="", &$photomagraphs_check)
{
  $this->db->select('*');
  $this->db->from('photomagraphs');
  $this->db->order_by("photo_id","desc");
  
  if( $pid!="" && is_numeric( $pid ) && ( $pagenum=="view" || $pagenum=="" ) )
  {
   $this->db->where('photo_id',$pid);
  }
  $this->db->order_by("photo_id", "desc");
  if( $pid=="page" && ( $pagenum>0 && $pagenum!="" && is_numeric( $pagenum ) ) )
  {
   $this->db->limit(16, (16*($pagenum)-1)+2);
   //$this->db->limit($this->per_page, (($pagenum)-1 * $this->per_page) + $offset);
  }
  else
  {
   $this->db->limit(16);
  }
  
  $query = $this->db->get();
    
  $result_array = $query->result_array();

  $this->db->flush_cache();

  $photo = reset( $result_array );

  if( in_array($photo['photo_id'],$photomagraph_check) )
  {
   $result_array = $this->get_photomagraph($photomagraph_check);
  }
  else
  {
   $photomagraph_check[] = $photo['photo_id'];
  }
  
  return $result_array;
}

Your help is hugely appreciated. Thanks.


Messages In This Thread
Pagination jumping by per_page value? - by El Forum - 08-23-2012, 04:57 PM
Pagination jumping by per_page value? - by El Forum - 08-23-2012, 05:36 PM
Pagination jumping by per_page value? - by El Forum - 08-23-2012, 05:46 PM
Pagination jumping by per_page value? - by El Forum - 08-23-2012, 11:35 PM
Pagination jumping by per_page value? - by El Forum - 08-24-2012, 02:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB