Welcome Guest, Not a member yet? Register   Sign In
Problem with pagination, need some help, new to CI (3 day)
#1

[eluser]nemanjanq[/eluser]
This is my code

Code:
function city()
    {
        $this->load->library('pagination');
        
        $this->db->where('city', $this->uri->segment(3));
        $this->db->from('companies');
        $number = $this->db->count_all_results();
        
        $config['base_url'] = base_url(). 'index.php/adresar/city/' . $this->uri->segment(3) . '/index';
        $config['total_rows'] = $number;
        $config['per_page'] = '5';
        
        $this->pagination->initialize($config);
        

        $this->load->model('companies_model');
        $this->companies_model->get_companies_fromcity($this->uri->segment(3));
        $data['query'] = $this->db->get('companies');
        
        // load the view
        $this->load->view('page_top_view', $data);
        $this->load->view('header_view', $data);
        $this->load->view('firma_grad_view', $data);
        $this->load->view('footer_view', $data);
    }

This function is "city", right now I have URL http://localhost/adresar/index.php/adresar/city/ which list out all companies (because there is no city in URL), but it should list no companies, right ?

and when I click on

http://localhost/adresar/index.php/adresar/city/Loznica

(loznica is name of city)

I get all companies from loznica but pagination is not working, I get:

Code:
1 2 3 >  Last ›

on bottom, and it generated corect but its not working, it list all my companies...

what I am doing wrong ? thanks!
#2

[eluser]nemanjanq[/eluser]
OK, I think I know what I did wrong. Will let you know.
#3

[eluser]nemanjanq[/eluser]
Ok, now everything is working, just my pagination links are not updated, nothing happend.

its always like this
Code:
1 2 3 >  Poslednja

here is the updated code

Code:
function grad ()
    {
        if (($this->uri->segment(3)) == '') {
            redirect('adresar/');
        }
        else {
            $this->load->library('pagination');
            
            $this->db->where('grad', $this->uri->segment(3));
            $this->db->from('firme');
            $broj_firmi_ugradu = $this->db->count_all_results();

            
            $config['base_url'] = base_url(). 'index.php/adresar/grad/' . $this->uri->segment(3) . '/index';
            $config['total_rows'] = $broj_firmi_ugradu;
            $config['per_page'] = '5';
            $config['first_link'] = 'Prva';
            $config['last_link'] = 'Poslednja';
            $config['full_tag_open'] = '<p class="paginacija">';
            $config['full_tag_close'] = '</p>';
            
            $this->pagination->initialize($config);
            
            $data['p_grad'] = $this->uri->segment(3);
            
            $this->db->where('grad', $this->uri->segment(3));
            $data['query'] = $this->db->get('firme', $config['per_page'], $this->uri->segment(5));
            
            // load the view
            $this->load->view('page_top_view', $data);
            $this->load->view('header_view', $data);
            $this->load->view('firma_grad_view', $data);
            $this->load->view('footer_view', $data);
        }
    }
#4

[eluser]therealmaloy[/eluser]
nemanjanq

in your model, have you specified the offset and limit for the function that return the records.

you need that Smile
#5

[eluser]nemanjanq[/eluser]
Hi, check my updated code, above your post, I fixed that. Now I have problem with

Code:
&lt;?php echo $this->pagination->create_links(); ?&gt;

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB