在这个分页中计算行数?

时间:2011-08-16 08:09:41

标签: php codeigniter count rownum

我在其中使用codeigniter和类(library) pagination,为什么不在我的示例column # in pagination 5中设置showing? 在分页5中显示的是 - > 13 to 16 of 16但是分页5中的列#是 - > 13 14 15
如果最后一次分页是一行,则会出现此问题。

示例: in this page you go to pagination 5this 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);   
    }

1 个答案:

答案 0 :(得分:0)

if(($ curr_offset + $ config ['per_page'])&lt;($ config ['total_rows'] -1))

应该是

if(($ curr_offset + $ config ['per_page'])&lt; =($ config ['total_rows'] -1))