【问题标题】:Not displaying the row numbers continuosly while using pagination使用分页时不连续显示行号
【发布时间】:2017-08-29 08:52:16
【问题描述】:

我在我的网站中使用分页,但问题是它没有连续显示行号。

在我的网页中,我每页显示 10 行。单击下一页它再次显示从 1 开始的行号。实际上它应该从页面中的 11 开始,但它再次显示为 1。

控制器:

function index()
{
    $config = array();
    $config["base_url"] = base_url("index.php/blogs/index");
    $config["total_rows"] = $this->blogs_model->record_count();
    $config["per_page"] = 11;
    $config['num_links'] = 20;
    $config['first_link'] = 'First';
    $config['last_link'] = 'Last';
    $this->pagination->initialize($config);
    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data['records'] = $this->blogs_model->get_blogs($config["per_page"], $page);
    $data['comments'] = $this->blogs_model->getcommentscount($this->uri->segment(3));
    $data["links"] = $this->pagination->create_links();
    $data['mainpage'] = 'blogs';
    $data['mode'] = 'all';
    $this->load->view('templates/template', $data);
}

型号:

function get_blogs($limit, $start)
{
    $this->db->limit($limit, $start);
    $this->db->Select('blogs.*');
    $this->db->From('blogs');
    $this->db->where(array('blogs.status' => 1));
    $this->db->order_by("date", "desc");
    $q = $this->db->get();
    if ($q->num_rows() > 0) {
        return $q->result();
    } else {
        return false;
    }
}

【问题讨论】:

标签: php codeigniter pagination


【解决方案1】:

在查看其工作正常的情况下进行了一些更改。这是单击分页链接后正确显示 s.no 的最新代码。

<?php if(count($records) > 0) { ?>
            <table>
                <thead>
                    <tr>
                        <th scope="col">S.No</th>
                        <th scope="col">Blog Title</th>                         
                    </tr>
                </thead>

                <tbody>

                <?php $i = $this->uri->segment(3)+0; foreach ($records as $row){ $i++; ?>
                    <tr>                                                        
                        <td class="align-center"><?php echo $i;?></td>
                        <td><?php echo $row->blog_title;?></td>                     

                    </tr>

                 <?php  } ?>

                </tbody>
            </table>
            <?php } ?>
            <div class="pagination"><?php echo $this->pagination->create_links(); ?></div>  

【讨论】:

  • 经过 3 天的测试和无数种方法的尝试,除了您的方法之外,没有任何效果。但稍作改动,因为在我的情况下,我使用了$i = $this-&gt;uri-&gt;segment(4)+1;...谢谢
【解决方案2】:

一切似乎都很好。您可以像这样更改Model 的功能。

function get_blogs($limit, $start) {
    $this->db->select('*');
    $this->db->from('blogs');
    $this->db->where('status', 1);
    $this->db->order_by("date", "DESC");
    $this->db->limit($limit, $start);
    $q = $this->db->get();

    if ($q->num_rows() > 0) {
        return $q->result();
    } else {
        return false;
    }
}

【讨论】:

  • $config['uri_segment'] = 3; 在分页初始化之前将此添加到配置中。
  • 好的。然后确保您已正确加载这两个。 $this-&gt;load-&gt;helper("url"); $this-&gt;load-&gt;library("pagination"); 最好是 autoload 或者在 Controller__construct() 方法中加载它们。
  • 是的,我已经加载了这两个网址
  • 那么我确定问题出在这一行$page = ($this-&gt;uri-&gt; segment(3)) ? $this-&gt; uri-&gt;segment(3) : 0;
  • echo $page; exit 检查
猜你喜欢
  • 1970-01-01
  • 2023-04-09
  • 1970-01-01
  • 2022-12-11
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 2018-07-27
  • 1970-01-01
相关资源
最近更新 更多