Search code examples
phpcodeignitercountrownum

Counting rows in this pagination?


I use of codeigniter and class (library) pagination in it, why not set in my example, column # in pagination 5 with showing?
showing in pagination 5 is-> 13 to 16 of 16 but column # in pagination 5 is -> 13 14 15.
This problem occur In befor last pagination, if last pagination is a row.

EXAMPLE: in this page you go to pagination 5 or this is direct link to pagination 5

function show($offset = 0) 
    {

    $this->admin_model->header();

    $this->load->library('pagination');
    //$this->load->library('Jquery_pagination');
    $config['base_url'] = base_url().'admin/accommodation/show';
    $config['uri_segment'] = 4;
    $config['total_rows'] = $this->db->count_all('hotel_submits');
    $config['per_page'] = '3';
    //$config['div'] = '#num_count'; /* Here #content is the CSS selector for target DIV */
    $config['num_links'] = 10000000;
    $config['full_tag_open'] = '<div id="pagination">';
    $config['full_tag_close'] = '</div>';

    $this->pagination->initialize($config);

    $offset = (int) $offset; // just to make sure nothing funky gets in here
    $data['results'] = $this->db->query("SELECT @rownum:=@rownum+1 rownum, t.*
    FROM (
        SELECT *
        FROM hotel_submits
        ORDER BY id desc
        LIMIT $offset, 3    
    ) t,
    (SELECT @rownum:=0) r");

    $data['offset'] = $offset;

    ///////////////////////////HERE-START///////////////////////////////

    $curr_offset = $this->uri->segment($config['uri_segment']);
        $info = 'showing: ' . ( $curr_offset + 1 ) . ' to ' ;

        if( ( $curr_offset + $config['per_page'] ) < ( $config['total_rows'] -1 ) )
            $info .= $curr_offset + $config['per_page'];
        else
            $info .= $config['total_rows'];

        $info .= ' of ' . $config['total_rows'];

        $data['num_count'] = $info;

    ///////////////////////////HERE-END///////////////////////////////


    $this->load->view('admin/accommodation_submit_show', $data);   
    }

Solution

  • if( ( $curr_offset + $config['per_page'] ) < ( $config['total_rows'] -1 ) )

    should be

    if( ( $curr_offset + $config['per_page'] ) <= ( $config['total_rows'] -1 ) )