我尝试使用codeigniter在我的网站上进行分页,这个分页的total_rows是正确的,但结果是错误的,结果只显示从数据库的第一个位置到尽可能多的total_rows的排序,我有一个例子total_rows 3 with codition where field = TRUE但是,分页只会显示3在数据库中最高的位置。不遵循field = TRUE
的条件我有这样的控制器
function __construct(){
parent::__construct();
// konfigurasi helper & library
$this->load->helper('url');
$this->load->library('pagination');
$this->load->database();
}
public function index()
{
$this->model_security->getsecurity();
$isi['content'] = 'data_pelamar/tampiltotal_dipanggil';
$isi['judul'] = 'Data Pelamar';
$isi['sub_judul'] = 'Total dipanggil';
$isi['data'] = $this->db->get('data_pribadi');
// konfigurasi class pagination
$config['base_url']=base_url()."index.php/Total_dipanggil/index";
$config['total_rows']= $this->db->query("SELECT * FROM data_pribadi WHERE status_wawancara='sudah' and status='';")->num_rows();
$config['per_page']= 3;
$config['num_links'] = 2;
$config['uri_segment']=3;
//Tambahan untuk styling
$config['full_tag_open'] = "<ul class='pagination'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$config['first_link']='< Pertama ';
$config['last_link']='Terakhir > ';
$config['next_link']='> ';
$config['prev_link']='< ';
$this->pagination->initialize($config);
// konfigurasi model dan view untuk menampilkan data
$this->load->model('Model_page');
$isi['data_dipanggil']=$this->Model_page->getAll($config);
$this->load->view('halaman_menu',$isi);
}
我得到了这样的看法
<table id="dynamic-table" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th> No </th>
<th> Kode Data Pribadi </th>
<th> Nama Lengkap </th>
<th> Jenis Kelamin </th>
<th> Tanggal Lahir </th>
<th> No Telepon </th>
<th> ID </th>
<th> Tools </th>
<th> Status </th>
</tr>
</thead>
<tbody>
<tr>
<?php
$no = 1;
foreach ($data_dipanggil as $row){
?>
<td> <?php echo $no++;?> </td>
<td> <a href="<?php echo base_url();?>index.php/Detail_pelamar/pindah/<?php echo $row->kode_data_pribadi ;?>"><?php echo $row->kode_data_pribadi ;?> </a>
</td>
<td> <?php echo $row->nama_lengkap ;?></a> </td>
<td> <?php echo $row->jenis_kelamin ;?> </td>
<td> <?php echo $row->tanggal_lahir ;?> </td>
<td> <?php echo $row->no_telpon ;?> </td>
<td> <?php echo $row->id ;?> </td>
<td>
<a href="<?php echo base_url();?>index.php/Total_diterima/terima_pelamar/<?php echo $row->kode_data_pribadi ;?>" onclick="return confirm('apakah anda yakin ingin menerima data pelamar ini???') ";>
Diterima
</a>
<br><br>
<a href="<?php echo base_url();?>index.php/Total_ditolak/tolak_pelamar/<?php echo $row->kode_data_pribadi ;?>" onclick="return confirm('apakah anda yakin ingin menolak data pelamar ini???') ";>
Ditolak
</a>
<br><br>
<a href="<?php echo base_url();?>index.php/Total_pelamar/delete/<?php echo $row->kode_data_pribadi; ?>" onclick="return confirm('apakah anda yakin ingin menghapus data ini???'); ">
Hapus Data
</a>
</td>
<td>
Sudah Dipanggil
</td>
</tr>
<?php
$sql = "SELECT COUNT(*) FROM `data_pribadi` WHERE status_wawancara = 'sudah' && status = '';";
$query = $this->db->query($sql);
$result = $query->row_array();
$count = $result['COUNT(*)'];
if($count < 1){ ?>
<tr>
<td colspan="9" align="center">
Data Tidak ada!
</td>
</tr>
<?php }
}
?>
</tbody>
<?php
echo $this->pagination->create_links();
?>
</table>
答案 0 :(得分:0)
而不是这一行
$isi['data_dipanggil']=$this->Model_page->getAll($config);
更改为
$isi['data_dipanggil']=$this->Model_page->getAll($config['per_page']);
然后在你正在编写的模型中,getall()方法传递任何变量,如
public getall($pagination)
{
// query
//use limit condition
$this->db->limit($pagination)
}