【发布时间】:2013-02-21 04:12:52
【问题描述】:
我正在为我的网站进行分页,我正在显示来自数据库上两个表的数据,我的页面中有分页,但它的行为不像它假设的那样,它不会改变页面。目前我在网页上显示了 16 条记录,并设置了$config['per_page'] = 1; 分页栏上升到 16,但它不会翻阅所有记录显示在页面上的页面。任何帮助将不胜感激这是我的代码:
控制器
<?php
class Result_controller extends CI_Controller{
function getall(){
$this->load->model('result_model');
$data['query'] = $this->result_model->result_getall();
// print_r($data['query']); die();
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/Surva/index.php/result_controller/getall';
$config['total_rows'] = $this->db->get('tblanswers, credentials')->num_rows();
$config['per_page'] = 1;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('tblanswers, credentials', $config['per_page'], $this->uri->segment(1, 0))->result_array();
$data['pagination'] = $this->pagination->create_links();
$this->load->view('result_view', $data);
}
}
?>
查看
<div>
<table border="1">
<tr>
<th>Name</th>
<th>Second Name</th>
<th>Phone</th>
<th>Email</th>
<th>Answer</th>
<th>Comment</th>
</tr>
<?php foreach ($query as $row): ?>
<tr>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->second_name; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->email; ?></td>
<td> <?php echo $row->answerA;?>
<?php echo $row->answerB;?>
<?php echo $row->answerC;?></td>
<td><?php echo $row->comment;?><br></td>
</tr>
<?php endforeach; ?>
</table>
<?php if (isset($pagination))
{
echo $pagination;
// echo "<pre>"; var_dump($query);
} ?>
型号
function result_getall(){
return $this->db->select('tblanswers.*,credentials.*')
->from('tblanswers, credentials')
->get()
->result_object();
【问题讨论】:
-
您是否在查询中设置了限制?同时显示您的型号代码。
-
模型是一个简单的获取所有功能
-
就是这个问题,模型需要限制和偏移,看我的回答。
-
检查 $this->uri->segment(1, 0) 返回的内容..
-
试试@karmafunk 的建议。我认为它会工作
标签: php codeigniter pagination