Welcome Guest, Not a member yet? Register   Sign In
Help with pagination class
#1

[eluser]skeletonfriend[/eluser]
I have problem with the pagination class....i have this listpage that shows all posted articles, in a list, divided by pages (pagination), in my sidebar, I have a dropdownlist that gives the user the opportunity to sort/filter the list.

Everything works fine, or at least to a 98% degree..but whenever I make a selection in the dropdownlist and the page reloads and adds the parameter "orderby", the pagination links doesn't seem to respond visually. They do work when I click on them, but the visual "you-are-here" doesn't work for some reason.

Code:
// Model

function getList($order = "", $num, $offset)
{
    if ($order != "")
    {
        switch ($order)
        {
            case 'date':
                $userOrderby = $this->db->orderby('a.date_created', 'desc');
                $userWhere = "";
                break;
                        
            case 'heading':
                $userOrderby = $this->db->orderby('a.name', 'asc');
                    $userWhere = "";
                break;
                        
            case 'picture':
                $userOrderby = $this->db->orderby('a.date_created', 'desc');
                $userWhere = $this->db->where('a.image <> ""');
                break;
                        
            case 'comments':
                $userOrderby = $this->db->orderby('comments', 'desc');
                $userWhere = "";
                break;
                        
            case 'all':
                $userOrderby = $this->db->orderby('a.date_created', 'desc');
                $userWhere = "";
                break;
                        
            default:
                $userOrderby = $this->db->orderby('a.date_created', 'desc');
                $userWhere = "";
                break;
        }
    }
        else
        {
                $userOrderby = $this->db->orderby('a.date_created', 'desc');
                $userWhere = "";
        }
        
    $this->db->select('a.id, a.name, a.date_created, a.author, COUNT(b.comment_id) AS comments');
    $this->db->from('it_news a');
    $this->db->join('it_news_comments b', 'a.id = b.news_id', 'left');
    $userWhere;
    $this->db->groupby('a.id, a.name, a.author');
    $userOrderby;
    $this->db->limit($num, $offset);
    $query = $this->db->get();
            
    if ($query->num_rows() > 0)
    {
        return $query->result_array();
    }
}


Code:
// Controller

function orderby()
{
    $config['base_url'] = base_url() . 'blog/orderby/' . $this->uri->segment(3);
    $config['total_rows'] = $this->db->count_all('it_news');
    $config['per_page'] = '20';
    $config['num_links'] = '5';
    $this->pagination->initialize($config);
            
    $num = $config['per_page'];
    $offset = $this->uri->segment(4);

    $this->template['blog_list'] = $this->blog_model->getList($this->uri->segment(3), $num, $offset);
    $this->template['blog_pager'] = $this->pagination->create_links();
    $this->_run('blog_page');
}


Can anyone spot the problem? I would really appreciate some help!
#2

[eluser]skeletonfriend[/eluser]
Is there anyone who has an idea? Please?
#3

[eluser]tonanbarbarian[/eluser]
i think the issue might be the pagination config
it looks like the issue is the uri_segment

by default pagination used $config['uri_segment'] = 3;
but you seem to be using $config['uri_segment'] = 4;
so try adding that to the pagination config and see if it works better
#4

[eluser]skeletonfriend[/eluser]
you were so correct, as simple as that! I found that within minutes after I posted the message....changed it to 4 and everything works just fine.




Theme © iAndrew 2016 - Forum software by © MyBB