-4

i cant make pagination in image gellery..i m new in codeigniter..can anyone write me the pagination code of this????____

controller-
public function gallery() {
    $data = array();
    $data['title'] = '। Gallery ।';
    $data['logo_image'] = $this->w_model->select_logo_image();
    $data['all_gallery_image'] = $this->w_model->select_all_gallery_image();
    $data['maincontent'] = $this->load->view('gallery', $data, true);
    $this->load->view('master', $data);
}    


model- 

   public function select_all_gallery_image() {
    $this->db->select('*');
    $this->db->from('image_gallery');
    $query_result = $this->db->get();
    $result = $query_result->result();
    return $result;
    }

1 Answer 1

0

in your controller do this

    $this->load->library('pagination');
    $this->load->library('table');
    $count = $this->db->get('tablename')->num_rows();//it's just a short cut, you need to do this in your model
    $config['base_url'] = base_url() . "index.php/controllername/functionname";
    $config['total_rows'] = $count;
    $config['per_page'] = 8;//data showing perpage
    $config['num_links'] = 4;//number of links of pagination.. 
    //note: don't rename any key of your config, it will not run if you do
    $this->pagination->initialize($config);//initialize your pagination, 


    $data['record'] = $this->db->get('image_gallery',8,$this->uri->segment(3));
    //in this code, the 8 is the limit of data per page,
    //the uri-segment is the 3 address of url starting your controller name, 
    //for example if your url is like this  
    //localhost/ci/index.php/controllername/functionname
    //the uri segment it will get the third segment of your url, the count on url start in controllername/(2nd)functionname/(3rd)
    $this->load->view("your view",$data);

after that in your view

<?php 
echo $this->table->generate($record);//pass the record to table..and it will automatically create a table, the header of this table is the column name of your table

echo $this->pagination->create_links(); //this will create the link of your pagination?>

hope it save you a lot of time

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.