Codeigniter 分页下一步按钮不起作用

发布于 2024-12-18 10:21:47 字数 4814 浏览 1 评论 0原文

我正在尝试显示数据库中的信息。我已将 $config['per_page'] 设置为 2,在我的视图文件中我可以看到我想要的信息,但是当我单击下一个按钮时它不会改变任何内容。数据库值保持不变,当前页面也仍然是第一页。

请您帮我解决这个问题好吗?

提前致谢:)

控制器:

 function index($id){                   
    $this->load->library('pagination');                                 
    $config['base_url'] = site_url().'Student_fee_status/index/'.$id;

    $this->db->select('*');
    $this->db->from('studentpayment1');
    $this->db->where('studentid', $id); 

    $query = $this->db->get('');
    $numrows=$query->num_rows();                    

    $config['total_rows'] = $numrows;
    $config['per_page'] = 2;
    $config['uri_segment'] = '2'; 
    $config['num_links'] = 20;
    $config['full_tag_open'] = '<div class="pagination" align="center">';
    $config['full_tag_close'] = '</div>';

    $this->pagination->initialize($config);                 
    $this->load->model('Mod_student_fee_status');

    $data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
    $data['main_content']='view_student_fee_status';

    $this->load->view('includes/template',$data);                   
}   

我的模型:

function fee_status($id,$perPage,$uri_segment) { 
    $this->db->select('*');
    $this->db->from('studentpayment1');
    $this->db->where('studentid', $id); 

    $getData = $this->db->get('', $perPage, $uri_segment);

    if($getData->num_rows() > 0)
        return $getData->result_array();
    else
        return null;
}

编辑

当页面首次加载时,链接如下所示 - http: //本地主机/sundial/Student_fee_status/index/1006/ 但是当我单击下一页时,它看起来像这样 - http://localhost/sundial/Student_fee_status/ index/1006/2

我的查看文件:

<h1>Payment Status</h1>     
<?php if(count($records) > 0) { ?>
    <table id="table1" class="gtable sortable">
        <thead>
            <tr> 
                <th>S.N</th>
                <th>Invoice ID</th>
                <th>Transaction Description</th>
                <th>Received Date</th>
                <th>Debit</th>
                <th>Credit</th>
                <th>Balance</th>
            </tr>
        </thead>

    <?php $i = $this->uri->segment(2) + 0; foreach ($records as $row){ $i++; ?>
        <tbody>
            <?php
                $mydate= $row['period'];
                $month = date("F",strtotime($mydate));
                $year = date("Y",strtotime($mydate));
            ?>
            <tr>
                <td><?php echo $i; ?>.</td>
                <td><?php echo $row['invoiceid'];?></td>
                <td><a href="<?php echo base_url(); ?>student_fee_status/fee_types/<?php echo $row['paymentid']; ?>" rel="1" class="newWindow" >Total Fee For <?php echo $month ;?>, <?php echo $year ;?>  </a></td>
                <td><?php echo $row['received_date'];?></td>
                <td><?php echo $row['totalamount'];?></td>
                <td><?php echo "0";?></td>
                <td><?php echo $row['totalamount'];?></td>
            </tr>
            <tr>
                <td><?php echo $i; ?>.</td>
                <td><?php echo $row['invoiceid'];?></td>
                <td>Payment Received </td>
                <td><?php echo $row['received_date'];?></td>
                <td><?php echo "0";?></td>
                <td><?php echo $row['amountpaid'];?></td>
                <td>
                    <?php
                        $balance=$row['totalamount']-$row['amountpaid']; 
                        if($balance>0){
                            echo "<font color=\"red\">$balance</font>";
                        }
                        else {
                            echo $balance;
                        }
                    ?>
                </td>
            </tr>
    <?php } ?>
        </tbody>
    </table>
<?php } ?>

<div class="tablefooter clearfix">
    <div class="pagination">
        <?php echo $this->pagination->create_links(); ?> 
    </div>                              
</div>

I am trying to display information from database. I have set $config['per_page'] to 2, in my view file I can see the information I want but when I click on the next button it doesn't change anything. The database values remain same and the current page remains the first page too.

Would you please kindly help me figure out the problem?

Thanks in Advance :)

Controller:

 function index($id){                   
    $this->load->library('pagination');                                 
    $config['base_url'] = site_url().'Student_fee_status/index/'.$id;

    $this->db->select('*');
    $this->db->from('studentpayment1');
    $this->db->where('studentid', $id); 

    $query = $this->db->get('');
    $numrows=$query->num_rows();                    

    $config['total_rows'] = $numrows;
    $config['per_page'] = 2;
    $config['uri_segment'] = '2'; 
    $config['num_links'] = 20;
    $config['full_tag_open'] = '<div class="pagination" align="center">';
    $config['full_tag_close'] = '</div>';

    $this->pagination->initialize($config);                 
    $this->load->model('Mod_student_fee_status');

    $data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);
    $data['main_content']='view_student_fee_status';

    $this->load->view('includes/template',$data);                   
}   

My Model :

function fee_status($id,$perPage,$uri_segment) { 
    $this->db->select('*');
    $this->db->from('studentpayment1');
    $this->db->where('studentid', $id); 

    $getData = $this->db->get('', $perPage, $uri_segment);

    if($getData->num_rows() > 0)
        return $getData->result_array();
    else
        return null;
}

EDIT

When the page first loads the link looks like this- http://localhost/sundial/Student_fee_status/index/1006/
but when I click on the next page it looks like this- http://localhost/sundial/Student_fee_status/index/1006/2

My View File:

<h1>Payment Status</h1>     
<?php if(count($records) > 0) { ?>
    <table id="table1" class="gtable sortable">
        <thead>
            <tr> 
                <th>S.N</th>
                <th>Invoice ID</th>
                <th>Transaction Description</th>
                <th>Received Date</th>
                <th>Debit</th>
                <th>Credit</th>
                <th>Balance</th>
            </tr>
        </thead>

    <?php $i = $this->uri->segment(2) + 0; foreach ($records as $row){ $i++; ?>
        <tbody>
            <?php
                $mydate= $row['period'];
                $month = date("F",strtotime($mydate));
                $year = date("Y",strtotime($mydate));
            ?>
            <tr>
                <td><?php echo $i; ?>.</td>
                <td><?php echo $row['invoiceid'];?></td>
                <td><a href="<?php echo base_url(); ?>student_fee_status/fee_types/<?php echo $row['paymentid']; ?>" rel="1" class="newWindow" >Total Fee For <?php echo $month ;?>, <?php echo $year ;?>  </a></td>
                <td><?php echo $row['received_date'];?></td>
                <td><?php echo $row['totalamount'];?></td>
                <td><?php echo "0";?></td>
                <td><?php echo $row['totalamount'];?></td>
            </tr>
            <tr>
                <td><?php echo $i; ?>.</td>
                <td><?php echo $row['invoiceid'];?></td>
                <td>Payment Received </td>
                <td><?php echo $row['received_date'];?></td>
                <td><?php echo "0";?></td>
                <td><?php echo $row['amountpaid'];?></td>
                <td>
                    <?php
                        $balance=$row['totalamount']-$row['amountpaid']; 
                        if($balance>0){
                            echo "<font color=\"red\">$balance</font>";
                        }
                        else {
                            echo $balance;
                        }
                    ?>
                </td>
            </tr>
    <?php } ?>
        </tbody>
    </table>
<?php } ?>

<div class="tablefooter clearfix">
    <div class="pagination">
        <?php echo $this->pagination->create_links(); ?> 
    </div>                              
</div>

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

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

发布评论

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

评论(1

冷夜 2024-12-25 10:21:47

您告诉分页库使用 $config['uri_segment'] = '2'; - uri 的第二段。

当这是您的网址时: http://localhost/sundial/Student_fee_status/index/1006/我猜这是你的base_url: http://localhost/sundial/

在在这种情况下,您的段是:

  1. Student_fee_status - 您的控制器
  2. 索引 - 您正在调用的控制器方法
  3. 1006 - 您使用它调用控制器方法的参数
  4. 应该是分页的参数

尝试这个

$config['uri_segment'] = ' 4';

而不是

$config['uri_segment'] = '2';

编辑

$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);

我认为这一行包含另一个错误。

您向模型传递分页库使用的 uri_segment 信息。现在应该是 4。但是,您的模型使用此值来指定查询中的偏移量。这意味着您始终在查询中输入偏移量 4。但我认为你真正想做的是,将第四个 uri_segment 的 VALUE 传递给模型。

我会尝试这个:

 $data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$this->uri->segment($config['uri_segment']));

You are telling the pagination library to use $config['uri_segment'] = '2'; - the second segment of your uri.

When this is your url: http://localhost/sundial/Student_fee_status/index/1006/ I am guessing this is your base_url: http://localhost/sundial/

In this case your segments are:

  1. Student_fee_status - your controller
  2. index - the controllers method you are calling
  3. 1006 - the argument you are calling the controllers method with
  4. this should be the argument for pagination

Try this

$config['uri_segment'] = '4';

instead of

$config['uri_segment'] = '2';

edit:

$data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$config['uri_segment']);

I think this line contains another error.

You pass your model the information which uri_segment is used by the pagination library. That should be 4 now. However, your model uses this value to specify an offset in your query. This means you always put an offset of 4 into your query. But I think what you really want to do is, pass the model the VALUE of the 4th uri_segment.

I would try this instead:

 $data['records']= $this->Mod_student_fee_status->fee_status($id,$config['per_page'],$this->uri->segment($config['uri_segment']));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文