计算分页中的行数并显示它?

发布于 2024-11-29 14:12:08 字数 1979 浏览 1 评论 0原文

我在其中使用了 codeigniter 和类 (library) pagination
为什么此代码不适用于分页中的计数行,例如:

现有行:4 ->显示第 1 至 4 条,共 9 条

现有行:4 ->显示第 4 至 8 个,共 9 个

现有行:1 ->显示第 8 到 9 个,共 9 个

以及

其他


$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'] = '4';
    //$config['div'] = '#num_count'; /* Here #content is the CSS selector for target DIV */
    $config['num_links'] = 10000;
    $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, 4    
    ) t,
    (SELECT @rownum:=0) r");

/////////////////////////////////////////////////////////////////

$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;

/////////////////////////////////////////////////////////////////

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

此代码的输出是:of 9 |

I use of codeigniter and class (library) pagination in it.
Why this code don't work for counting rows in pagination, like:

Existing row: 4 -> Showing 1 to 4 of 9

or

Existing row: 4 -> Showing 4 to 8 of 9

or

Existing row: 1 -> Showing 8 to 9 of 9

and

other

$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'] = '4';
    //$config['div'] = '#num_count'; /* Here #content is the CSS selector for target DIV */
    $config['num_links'] = 10000;
    $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, 4    
    ) t,
    (SELECT @rownum:=0) r");

/////////////////////////////////////////////////////////////////

$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;

/////////////////////////////////////////////////////////////////

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

The output this code is: of 9 |

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2024-12-06 14:12:08

在多个地方:

$info .= 
      ^

In multiple places:

$info .= 
      ^
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文