Welcome Guest, Not a member yet? Register   Sign In
A Pagination Question
#1

[eluser]zeedy2k[/eluser]
Quick question I hope someone can answer... I have pagination working perfect on one site that uses a straight query, no WHERE statements... When I copy the same code across to another project with WHERE statements the pagination doesnt work.

http://www.findacarni.com/index.php and just click search should bring up 30 results 10 per page but when you choose to goto second page it says it cant find any results...

What is baffling me is that its the same code as the other site and as below...

Code:
function Search()
    {
        parent::Controller();    
        $this->load->helper('text');
        $this->load->library('pagination');
    }
    function index()
    {
        $model = $this->input->post('models');
        $minprice = $this->input->post('minprice');
        $maxprice = $this->input->post('maxprice');
        $orderby = $this->input->post('orderby');
        $location = $this->input->post('location');
        $manufacturer = $this->input->post('manufacturers');
        $countit = $this->db->query("SELECT * FROM `vehicles` WHERE `active` = 'Y' AND `manufacturer` LIKE '%$manufacturer%' AND `model` LIKE '%$model' AND `location` LIKE '%$location' AND `price` >= '$minprice' AND `price` <= '$maxprice' ORDER BY `price` $orderby");
        $count = $countit->num_rows();
        if ($count == "0"){
            $data['pagetitle'] = $this->config->item('sitename')." No Vehicles Found";
            $this->load->view('searchnoresults',$data);
        } else {
        $config['base_url'] = site_url('search/index');
        $config['total_rows'] = $count;
        $config['per_page'] = 10;
        $config['uri_segment'] = 3;
        $config['next_link'] = 'Next &gt;';
        $config['prev_link'] = '&lt;Previous';
        $this->pagination->initialize($config);
        $num = $config['per_page'];
        $offset = $this->uri->segment(3);
        
        $this->db->where('active', 'y');
        $this->db->like('manufacturer', $manufacturer);
        $this->db->like('model', $model);
        $this->db->like('location', $location);
        $this->db->where('price >=', $minprice);
        $this->db->where('price <=', $maxprice);
        $this->db->orderby('price', $orderby);
        $data['query']= $this->db->get('vehicles', $num, $offset);
        
        $data['count'] = $count;
        $data['links']=$this->pagination->create_links();
        $data['pagetitle'] = $this->config->item('sitename')." : ".$count." Vehicles Found";
        $this->load->view('searchresults',$data);
        }
    }

Any help with this appreciated...

Robert
#2

[eluser]tonanbarbarian[/eluser]
answer is pretty simple
you are using some post methods to generate the filtering in the count
but when you click on the pagination links they do not post that data.
i would recommend storing the filter selections in the session and retrieving them if no post data is set
#3

[eluser]zeedy2k[/eluser]
Excellent thanks m8... I done it how you suggested in a session and it work great... Never really used pagination before this and the other project...

Thanks again
Robert

[quote author="tonanbarbarian" date="1201447102"]answer is pretty simple
you are using some post methods to generate the filtering in the count
but when you click on the pagination links they do not post that data.
i would recommend storing the filter selections in the session and retrieving them if no post data is set[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB