Welcome Guest, Not a member yet? Register   Sign In
simple codeignier pagination problem
#1

[eluser]alectrash[/eluser]
I have a problem with the codeigniter pagination class

I have a page tags showing items from a database, images, videos etc

this is function tags from my controller page 'gallery'.

I want pagination to be like http://mydomain.com/gallery/tags/cars/5

i.e Get out of all database all items tagged as "cars" and show in sets of 5 from 5 onwards. The code works but pagination does not display properly.

because I have 7 items tagged as cars when I click on http://mydomain.com/gallery/tags/cars/5 i can see only items 5-7 but the pagination links which are showing at the top of the page are like so

Code:
&nbsp;<b>1</b>&nbsp;<a href="/gallery/tags/ioct/5">2</a>&nbsp;<a href="/gallery/tags/ioct/5">&gt;</a>&nbsp;

the 1 should be a link and the two should be bold since were on page 2 of results but its not working.

any ideas anybody, really stuck.

In my controller I have the following.

Code:
function tags()
{

$data['tag'] = $this->uri->segment(3);
    $data['itemnumber'] = $this->uri->segment(4);
    
    //get query for all digital art like tag received
    $data['query'] = $this->db->like('dbtags', $data['tag'])->order_by("dbdate", "desc")->where('dbstatus', 'published')->get('tblmedia');
  
    $item_count = count($data['query']->result());
  
    if($item_count < 1)
    {
      redirect('gallery');
    }
    
    $config['base_url'] = '/gallery/tags/' . $data['tag'];
    $config['total_rows'] = $item_count;
    $config['per_page'] = '5';
    $data['per_page'] = $config['per_page'];
    
    $this->pagination->initialize($config);
    if($item_count > $config['per_page'])
    {
     $this->pagination->create_links();  
    }
    
    $this->load->view('gallery_tag_view', $data);
}
#2

[eluser]Dr.Dan[/eluser]
Code:
$config['uri_segment'] = 5;
#3

[eluser]alectrash[/eluser]
thankyou dr dan just what the doctor (you maybe) ordered, lol!

I added

Code:
$config['uri_segment'] = '4';

function in my controller now looks like this:

Code:
function tags()
{
    $data['menuitem'] = $this->uri->segment(1);
    $data['tag'] = $this->uri->segment(3);
    $data['itemnumber'] = $this->uri->segment(4);
    
    //get query for all digital art like tag received
    $data['query'] = $this->db->like('dbtags', $data['tag'])->order_by("dbdate", "desc")->where('dbstatus', 'published')->get('tblmedia');
  
    $item_count = count($data['query']->result());
  
    if($item_count < 1)
    {
      redirect('gallery');
    }
    
    $config['base_url'] = '/gallery/tags/' . $data['tag'];
    $config['total_rows'] = $item_count;
    $config['uri_segment'] = '4';
    $config['per_page'] = '5';
    
    $data['per_page'] = $config['per_page'];
    
    $this->pagination->initialize($config);
    if($item_count > $config['per_page'])
    {
     $this->pagination->create_links();  
    }
    
    $this->load->view('gallery_tag_view', $data);
    
}

hope this helps somebody out one day!
#4

[eluser]SamCris[/eluser]
THANKS DR.DO & ALECTRASH!!!

it just did help me out! i had the same problem!!!
i even posted a reply on one of the forums regarding my problem and a minute later i decided to search the forum... and to make things short, i found this!

thanks for posting alectrash!!

im just carried away cuz i got stuck here last night which worried me alot! thanks guyz!

now im back to work!

peace out!
#5

[eluser]alectrash[/eluser]
no problem man. enjoy ci!




Theme © iAndrew 2016 - Forum software by © MyBB