为什么我在同一页面中获取所有数据?
该函数正在工作,因为它将页面(1,2,3)显示为数据库表中的数据数。但是在一页中显示数据。
我的应用程序的控制器页面调用引导程序分页
public function reportTransaction(){
//pagination settings followed from that tutorial
//base url defined application
$config['base_url'] = site_url('inventory/reportTransaction');
//code that gets rows from the transaction model
$config['total_rows'] = $this->transactionLog->countAll();
//defined per page as 5
$config['per_page'] = 5;
$config["uri_segment"] = 3;
$choice = $config["total_rows"] / $config["per_page"];
$config["num_links"] = ceil($choice);
//echo $config["num_links"];
//config for bootstrap pagination class integration
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
//call the model function to get the transaction data
$data['posts'] = $this->transactionLog->get_report();
$data['pagination'] = $this->pagination->create_links();
//print_r($data['posts']);
//load the department_view
$this->load->view('admin/reportTransaction', $data);
$this->header();
$this->footer();
}
在控制器中调用的模型
function get_report($limit = null)
{
if ($limit != null) {
$this->db->limit($limit['limit'], $limit['offset']);
}
$q = $this->db->query("SELECT `transaction`.`transaction_id`, ABS(`cost`) as cst,`transaction`.`date_posted`, ABS(`unit`) as unt, `detail`.`name` as sam, `product`.`productName` as pam, `transaction`.`type` FROM `transaction` INNER JOIN `detail` ON `detail`.`type`=`transaction`.`type` INNER JOIN `product` ON `product`.`product_id`=`transaction`.`product_id`");
// $q = $this->db->get($this->table);
if ($q->num_rows() > 0) {
foreach ($q->result() as $row)
{
$data[] = $row;
}
}
return $data;
}
function countAll()
{
return $this->db->count_all($this->table);
}
查看显示控制器数据的应用程序的页面! 这是在同一页面中显示数据的表
<table class="table tablesorter table-bordered table-hover table-striped sortable">
<thead>
<tr>
<th>S/B Name</th>
<th>Product Name</th>
<th>Unit</th>
<th>Date Posted</th>
</tr>
</thead>
<tbody>
<?php $i=1; foreach($posts as $post): ?>
<tr <?=($i % 2 == 0) ? 'class="even"' : '' ?>>
<td><?=$post->sam?></td>
<td><?=$post->pam?></td>
<td><?=$post->unt?></td>
<td><?=$post->date_posted?></td>
</tr>
<?php $i++; endforeach; ?>
</tbody>
</table>
<div class="row">
<div class="col-md-12 text-center">
<p><?php echo $pagination; ?></p>
</div>
</div>
</div>
到达系统的问题 所有数据都显示在同一页面中 分页页码根据数据增加,但数据显示在同一个表中
答案 0 :(得分:0)
将get_report()
更改为以下
public function get_report($segment,$per_page)
{
$data = array();
$q = $this->db->query('SELECT `transaction`.`transaction_id`, ABS(`cost`) as cst,`transaction`.`date_posted`, ABS(`unit`) as unt, `detail`.`name` as sam, `product`.`productName` as pam, `transaction`.`type` FROM `transaction` INNER JOIN `detail` ON `detail`.`type`=`transaction`.`type` INNER JOIN `product` ON `product`.`product_id`=`transaction`.`product_id` LIMIT '.$segment.', '.$per_page);
if ($q->num_rows() > 0) {
$data = $q->result_array()
}
return $data;
}
现在使用LIMIT
参数
$data['posts'] = $this->transactionLog->get_report($data['page'],$config['per_page']);
现在检查