【发布时间】:2017-11-08 12:45:01
【问题描述】:
我创建了一个搜索功能,我想在我已经尝试但无法正常工作的结果表中使用分页。我只想显示 10 行,但是当我尝试它时不起作用。
我在https://codeigniter.com/ 中阅读了如何分页,但我仍然不明白如何在我的代码中使用它:
$config['base_url'] = '';
$config['total_rows'] = ;
这是我的代码:
控制器:
function __construct()
{
parent::__construct($securePage=false);
$this->load->helper('form');
$this->load->model('tracking_model');
}
function index()
{
$this->load->view('tracking_view');
$this->load->library('pagination');
}
function searchTiket(){
// Retrieve the posted search term.
$noTicket = $this->input->post('trackTicket');
$monthTicket = $this->input->post('trackMonth');
$yearTicket = $this->input->post('trackYear');
// Use a model to retrieve the results.
//pengaturan pagination
$config['base_url'] = base_url().'';
$config['total_rows'] = '200';
$config['per_page'] = '5';
//inisialisasi config
$this->pagination->initialize($config);
//buat pagination
$data['page'] = $this->pagination->create_links();
// Use a model to retrieve the results.
$data["result"]= $this->tracking_model->searchTiket($config['per_page'],$noTicket,$monthTicket,$yearTicket);
// Pass the results to the view.
$this->load->view('tracking/ticket_list_view',$data);
}
查看:
<div>
<center>
<?php if(empty($result)){
echo '<h2>Data not found!</h2>';
}else{
?>
<table border='1' Width='1000'>
<tr bgcolor= #ff9900>
<th style="color: white"> No. Tiket </th>
<th style="color: white"> Kategori </th>
<th style="color: white"> Status </th>
<th style="color: white"> Tanggal dibuat </th>
<th style="color: white"> Tanggal masuk ke IT </th>
<th style="color: white"> Estimasi Selesai </th>
<th style="color: white"> Tindakan </th>
</tr>
<?php
foreach($result as $row){?>
<?php
if ($row->Status =="OPEN") {
$image = '<img alt="Brand" src="assets/img/remind.png" width="25" height="25" /> Reminder';
} elseif ($row->Status =="Masih menunggu approval Atasan" || $row->Status =="Masih menunggu approval PIC HO") {
$image = '<img alt="Brand" src="assets/img/fast_forward.png" width="25" height="25" /> Percepat';
} elseif($row->Status =="Sudah Selesai"){
$image = '<img alt="Brand" src="assets/img/Reopen.png" width="25" height="25" /> Reopen';
} else {
$image ="";
}
?>
<tbody>
<tr>
<!-- <td bgcolor= #fff><?php echo $row->ticket_id; ?></td> -->
<td><a id="btn_preview" action="<?php echo base_url() ?>tracking/showDetail?ticket_id=<?php echo $row->ticket_id; ?>"><?php echo $row->ticket_id; ?></a></td>
<td bgcolor= #fff><?php echo $row->name; ?></td>
<td bgcolor= #fff><?php echo $row->Status; ?></td>
<td bgcolor= #fff><?php echo $row->created_time; ?></td>
<td bgcolor= #fff><?php echo $row->start_IT; ?></td>
<td bgcolor= #fff><?php echo $row->estimasi_selesai; ?></td>
<td bgcolor= #fff><?php echo $image; ?></td>
</tr>
</tbody>
<?php }?>
</table>
<div class="halaman">Halaman : <?php echo $page;?></div>
</center>
</div>
<?php
}
?>
型号:
function searchSpv()
{
$findTicket=$this->db->query("my query");
return $findTicket->result();
}
【问题讨论】:
-
您当前的输出是多少?显示了多少行?
-
我希望每页只显示 10 行,但所有行都显示在第一页。
-
你能发布你的模型代码吗?
-
我已经添加了我的型号代码@AdhanTimothyYounes
-
您的查询是什么?
标签: php html codeigniter pagination