Welcome Guest, Not a member yet? Register   Sign In
Weird pagination issue, a little help here
#1

[eluser]hyperfire[/eluser]
Hi there

I have this search function, witch is very simple and looks like it return the correct results, but the pagination is stuck at page1 no matter what page im browsing (i have only two page in this case).
The code is simple, take a look:

controller
Code:
function search()
    {
        $this->load->library('pagination');
        
        $sStr            = $_POST;
        $sRequestData     = serialize($sStr);
        $sResultsPP        = 5;
        $sOffset         = $this->uri->segment(4);
        
        if (!$this->session->userdata('s_string')) {
            $this->session->set_userdata('s_string',$sRequestData);            
        } else {
            $sData = unserialize($this->session->userdata('s_string'));
            $fData = unserialize($sRequestData);
            $fDatavar = (isset($fData['ss'])) ? $fData['ss'] : '' ;
            if($sData['ss'] != $fDatavar && $fDatavar != '') {
                $this->session->set_userdata('s_string',$sRequestData);
            }
        }        
        
        if (!$sOffset) {
            $sResults = $this->NewsModel->findArticles('s_string',0,$sResultsPP);
        } else {
            $sResults = $this->NewsModel->findArticles('s_string',$sOffset,$sResultsPP);    
        }
            
        $config['base_url']         =  base_url() . 'admin/news/search/';
        $config['total_rows']         = $this->NewsModel->nTotalFound;
        $config['per_page']         = $sResultsPP;
        $config['full_tag_open']     = '<p>';
        $config['full_tag_close']     = '</p>';        
        $this->pagination->initialize($config);
        
        $headerData['include_header']     = 'admin/admin_header';
        $headerData['include_menu']     = 'admin/admin_menu';
        
        $this->load->view('admin/_header', $headerData);
                    
        $contentData['cats']             = $this->NewsModel->getSectionCats(TRUE);
        $contentData['list']             = $sResults;
        $this->load->view('backend/_list', $contentData);
        
        $this->load->view('admin/_footer');
    }


model
Code:
function findArticles($xData=NULL,$nLimit,$nOffSet)
    {
        $aData = unserialize($this->session->userdata($xData));

        if (!empty($aData['ss']))
            $aAnd[] = "title LIKE '%{$aData['ss']}%'";

        $sAnd = implode(" AND ",$aAnd);

        $sSelectArticles = "SELECT SQL_CALC_FOUND_ROWS id,title,area  ".
                           "dt_post as dt_post ".
                           "FROM news ".
                           "WHERE $sAnd ".
                           "LIMIT $nLimit,$nOffSet";
        
        
        $query = $this->db->query($sSelectArticles);

        $nTotalFound = $this->db->query("SELECT FOUND_ROWS() as found");
        $nAll = $nTotalFound->row();
        $this->nTotalFound = $nAll->found;
        
        return $query->result();
    }


pagination shows correctly like this on page one (6 registers):

1 2 >

But when clicked on the second item, pagination remains on item 1 as selected, even with the correct data displayed.

I know I gotta be doing something wrong here, if anyone can point me a direction, it would be highly appreciated.

Thanks!
#2

[eluser]JoostV[/eluser]
Seems like you mixed up limit and offset. In you controller you use offset as the second argument and limt as the third.
[code]
$this->NewsModel->findArticles('s_string',$sOffset,$sResultsPP)
[code]

In your model it's the other way around.
[code]
findArticles($xData=NULL,$nLimit,$nOffSet)
[code]
#3

[eluser]gullah[/eluser]
I did the same thing when origionally setting this up and forgot
Code:
$config['uri_segment'] = 4;

I'm pretty sure in your case it would be 4
#4

[eluser]hyperfire[/eluser]
Hi,

Thanks drewtown, that just solved that misbehavior.
Also, thanks JoostV, that was also wrong.
I was so tired last nite...a little help sometimes is all we need.
Thanks!!




Theme © iAndrew 2016 - Forum software by © MyBB