【发布时间】:2019-01-18 07:45:01
【问题描述】:
当我显示此页面的数据表时,它可以工作,但是当我尝试添加分页时,它会出错。即使我有类似的问题,我在哪里可以找到解决方案
如何制作正确的脚本来显示基于分页的表格数据?
我的代码中的错误在哪里?
查看
<table class="table mt-3">
<thead class="table-danger text-center">
<tr>
<th scope="col">Kode</th>
<th scope="col">Type</th>
<th scope="col">Nama Barang</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody class="text-center table-primary">
<?php foreach ( $barang as $tb ) : ?>
<tr>
<td class="text-uppercase"><a href="" class="text-dark text-decoration-none"><?= $tb['barang_kode'] ?></a></td>
<td class="text-capitalize"><a href="" class="text-dark text-decoration-none"><?= $tb['type_nama'] ?></a></td>
<td class="text-capitalize"><a href="" class="text-dark text-decoration-none"><?= $tb['barang_nama'] ?></a></td>
<td>
<button id="btnGroupDrop1" type="button" class="btn btn-outline-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button>
<div class="dropdown-menu" aria-labelledby="btnGroupDrop1">
<a class="dropdown-item" href="<?= base_url(); ?>gudang/hapus_type/<?= $tb['barang_id']; ?>" onclick="return confirm('Yakin akan menghapus data ini ?');">Hapus</a>
<a class="dropdown-item" href="<?= base_url(); ?>gudang/ubah_type/<?= $tb['barang_id']; ?>">Ubah</a>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="container">
<?php // Tampilkan link-link paginationnya
echo $barang['pagination']; ?>
</div>
模型
$config['base_url'] = base_url('gudang/lihat_type');
$config['total_rows'] = $this->db->query($query)->num_rows();
$config['per_page'] = 5;
$config['uri_segment'] = 3;
$config['num_links'] = 3;
$config['full_tag_open'] = '<ul class="pagination pagination-sm m-t-xs m-b-xs">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = ' <i class="glyphicon glyphicon-menu-right"></i> ';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = ' <i class="glyphicon glyphicon-menu-left"></i> ';
$config['prev_tag_open'] = '<li>';
$config['prev_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>'; // End style pagination
$this->pagination->initialize($config); // Set konfigurasi paginationnya
$page = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;
$query .= " LIMIT ".$page.", ".$config['per_page'];
$data['limit'] = $config['per_page'];
$data['total_rows'] = $config['total_rows'];
$data['pagination'] = $this->pagination->create_links();
$data['barang'] = $this->db->query($query)->result_array();
return $data
【问题讨论】:
-
你遇到了什么错误?
-
@Haem 错误文件:/opt/lampp/htdocs/karyatohaputra/application/models/Gudang_model.php 行:149 功能:查询文件:/opt/lampp/htdocs/karyatohaputra/application/controllers/ Gudang.php 行:126 函数:getRelasi 文件:/opt/lampp/htdocs/karyatohaputra/index.php 行:315 函数:require_once
-
你应该edit你的问题的错误信息。
-
@YusufReza 为什么要在模型中添加分页,而不是在控制器中?另外,那个错误没有包含任何信息,没用,你能提供错误信息吗?
-
echo $barang['pagination'];这是错误的。仅使用$pagination显示链接
标签: php pagination config codeigniter-3