我试图从数据库显示信息。我设置$config['per_page']为2,在我的视图文件中,我可以看到我想要的信息,但当我点击下一个按钮时,它不会改变任何东西。数据库值保持不变,当前页也保持为第一页。
你能帮我解决这个问题吗?
Thanks in Advance:)
控制器:
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;
}
<标题>编辑当页面首次加载时,链接看起来像这样- http://localhost/sundial/Student_fee_status/index/1006/但是当我点击下一页时,它看起来像这样- 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>
标题>您告诉分页库使用$config['uri_segment'] = '2';
-您的uri的第二段。
当这是你的url: http://localhost/sundial/Student_fee_status/index/1006/我猜这是你的base_url: http://localhost/sundial/
在这种情况下,你的片段是:
- Student_fee_status -你的控制器
- index -你正在调用的控制器方法
- 1006 -使用 调用控制器方法的参数
- 这应该是分页的参数
Try this
$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']));