CodeIgniter のページング ライブラリを使用して大量のデータを処理したいと考えています。私はそれを実装しており、機能しています。しかし、問題があります。ページあたりのデータ量が一貫していません。
これは、私がそれを作成した簡単なコードです...
コントローラ
class Buku_con extends Controller {
public function Buku_con() {
parent::__construct();
$this->load->model('buku_model');
$this->load->library('pagination'); //call pagination library
}
function getBuku() {
//count the total rows of tb_book
$this->db->select('*');
$this->db->from('tb_book');
$getData = $this->db->get('');
$a = $getData->num_rows();
$config['base_url'] = base_url().'index.php/Buku_con/getBuku/'; //set the base url for pagination
$config['total_rows'] = $a; //total rows
$config['per_page'] = '10'; //the number of per page for pagination
$config['uri_segment'] = 3; //see from base_url. 3 for this case
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config); //initialize pagination
$data['detail'] = $this->buku_model->getBuku($config['per_page'],$this->uri->segment(3));
$this->load->view('buku_view', $data);
}
}
モデル
class Buku_model extends Model {
function Buku_model() {
parent::Model();
}
function getBuku($perPage,$uri) { //to get all data in tb_book
$title=$this->session->userdata('title');
$this->db->select('*');
$this->db->from('tb_book');
$this->db->where('title','$title');
$this->db->order_by('id','DESC');
$getData = $this->db->get('', $perPage, $uri);
if($getData->num_rows() > 0)
return $getData->result_array();
else
return null;
}
}
意見
if(count($detail) > 0) {
//... html for table .....
foreach($detail as $rows) {
echo
.... $rows['id'] .....
.... $rows['title'] .....
.... $rows['author'] .....
....
}
echo $this->pagination->create_links(); ....
ページングはうまく機能しますが、コントローラーで定義したように、ページごとのデータ量が一貫していません。問題は、モデルで使用するクエリ-タイトルのセッションが原因だと思います。
私はデータがページごとに10データを実行することを望んでいますが、ページ1ではわずか5データ、ページ2ではわずか4データであり、一貫性がありません。多分問題はビューにもあります。私は何をすべきか?どうもありがとうございました。