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

[eluser]bcarter[/eluser]
Hi there

Can anyone give me any ideas as to why the $config['first_tag_open'], $config['last_tag_open'] for the pagination does not change, no matter what page of the results I am on?

The results work fine and the pagination links work fine it's just that page 1 is always highlighted even if I'm on page 10.

Any help would be greatly received.

Thanks
#2

[eluser]InsiteFX[/eluser]
It's kind of hard to help you without seeing your pagination code!

Please use code tags when posting code!

InsiteFX
#3

[eluser]bcarter[/eluser]
Ok here goes

Controller
Code:
function results($query_id = 0, $offset = 0)
    {
        //Load helpers, profiler, models etc
        $this->load->model('enquiries/Search_model');
        $this->load->library('pagination');
        
        //Get the drop down options
        $data['course_list'] = $this->Search_model->get_courses();
        $data['status_list'] = $this->Search_model->get_enquiries_status();
        $data['source_list'] = $this->Search_model->get_enquiries_source();
        $data['referer_list'] = $this->Search_model->get_enquiries_referer();
        
        //Start to build the page
        $this->load->view('includes/head', $data);
        $this->load->view('enquiries/includes/header', $data);
        
        $this->my_functions->load_query($query_id);
        
        $query_array = array(
            'search'     => $this->input->get('search'),
            'type'        => $this->input->get('type'),
            'interest'     => $this->input->get('interest'),
            'source'     => $this->input->get('source'),
            'referer'     => $this->input->get('referer'),
            'status'    => $this->input->get('status'),
        );
        
        $data['values'] = $query_array;
        
        //How many results do we want to show per page?
        $config['per_page']         = 10;
        
        //Make the query
        $data['query_id']         = $query_id;
        $results                = $this->Search_model->search($query_array, $config['per_page'], $offset);
        
        //Thank you query, here's the data
        $data['results']         = $results['rows'];
        $data['num_results']     = $results['num_rows'];
            
        //For the pagination
        $this->load->library('pagination');
        $data['total_rows']         = $data['num_results'];
        $config['base_url']         = base_url() . "index.php/enquiries/enquiry/results/$query_id";
        $config['total_rows']         = $data['num_results'];
        $config['num_links']         = 9;
        $config['first_link']         = 'First';
        $config['last_link']         = 'Last';
        $config['full_tag_open']     = '<div id="pagination">';
        $config['full_tag_close']     = '</div>';
        $config['next_link']         = 'Next';
        $config['prev_link']         = 'Previous';
        
        //Create the pagination and get it loaded
        $this->pagination->initialize($config);
        
        //Load the views
        $this->load->view('enquiries/search_results_view', $data);
        $this->load->view('includes/footer');
        
    }

View
Code:
Search results display here...

&lt;?php echo $this->pagination->create_links() ?&gt;
#4

[eluser]bcarter[/eluser]
and the model...
Code:
&lt;?php

class Search_model extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function search($query_array, $limit, $offset)
    {        
        // results query
        $q = $this->db->select('m.noteId, d.id, d.type, d.company, d.contact, d.tel, d.email, d.interest, d.linkBDA, d.linkAdviser, d.source, d.referer, d.lead_status, d.submitted_by, d.comments, d.entryDate, n.when, n.entryDate AS last_event, n.notes, data_meta.first_name, data_meta.last_name')
            ->join('(SELECT enquiry, MAX(id) noteId FROM enquiries_events GROUP BY enquiry) m', 'd.id = m.enquiry', 'left')
            ->join('enquiries_events n', 'm.noteId = n.id', 'left')
              ->join('data_meta', 'd.submitted_by = data_meta.user_id', 'left')
            ->limit($limit, $offset)
            ->group_by('d.id')
            ->order_by('d.entryDate', 'DESC');
        
        if (strlen($query_array['type']) OR strlen($query_array['interest']) OR strlen($query_array['source']) OR strlen($query_array['referer']) OR strlen($query_array['status'])) {
            $where = "(company LIKE '%" . $query_array['search'] . "%' OR contact LIKE '%" . $query_array['search'] . "%' OR linkBDA LIKE '%" . $query_array['search'] . "%' OR linkAdviser LIKE '%" . $query_array['search'] . "%')";
        } else {
            $where = "company LIKE '%" . $query_array['search'] . "%' OR contact LIKE '%" . $query_array['search'] . "%' OR linkBDA LIKE '%" . $query_array['search'] . "%' OR linkAdviser LIKE '%" . $query_array['search'] . "%'";
        }
        
        if (strlen($query_array['type'])) {
            $where .= " AND type = '" . $query_array['type'] . "' ";
            //$type = $query_array['type'];
            //$where .= " AND type = '$type' ";
        }
        
        if (strlen($query_array['interest'])) {
            $where .= " AND interest = '" . $query_array['interest'] . "' ";
        }
        
        if (strlen($query_array['source'])) {
            $where .= " AND source = '" . $query_array['source'] . "' ";
        }
        
        if (strlen($query_array['referer'])) {
            $where .= " AND referer = '" . $query_array['referer'] . "' ";
        }
        
        if (strlen($query_array['status'])) {
            $where .= " AND lead_status = '" . $query_array['status'] . "' ";
        }
        
        $q->where($where);
        
        //Grab the results
        $results['rows'] = $q->get('enquiries_details d')->result();
        
        // count query
        $q = $this->db->select('COUNT(*) as count', FALSE)
            ->from('enquiries_details d');
        
        if (strlen($query_array['type']) OR strlen($query_array['interest']) OR strlen($query_array['source']) OR strlen($query_array['referer']) OR strlen($query_array['status'])) {
            $where = "(company LIKE '%" . $query_array['search'] . "%' OR contact LIKE '%" . $query_array['search'] . "%' OR linkBDA LIKE '%" . $query_array['search'] . "%' OR linkAdviser LIKE '%" . $query_array['search'] . "%')";
        } else {
            $where = "company LIKE '%" . $query_array['search'] . "%' OR contact LIKE '%" . $query_array['search'] . "%' OR linkBDA LIKE '%" . $query_array['search'] . "%' OR linkAdviser LIKE '%" . $query_array['search'] . "%'";
        }
        
        if (strlen($query_array['type'])) {
            $where .= " AND type = '" . $query_array['type'] . "' ";
            //$type = $query_array['type'];
            //$where .= " AND type = '$type' ";
        }
        
        if (strlen($query_array['interest'])) {
            $where .= " AND interest = '" . $query_array['interest'] . "' ";
        }
        
        if (strlen($query_array['source'])) {
            $where .= " AND source = '" . $query_array['source'] . "' ";
        }
        
        if (strlen($query_array['referer'])) {
            $where .= " AND referer = '" . $query_array['referer'] . "' ";
        }
        
        if (strlen($query_array['status'])) {
            $where .= " AND lead_status = '" . $query_array['status'] . "' ";
        }
        
        $q->where($where);
        
        $tmp = $q-> get()->result();
        
        $results['num_rows'] = $tmp[0]->count;
            
        return     $results;    
    }

Thanks
#5

[eluser]InsiteFX[/eluser]
For 1 why are you loading the Pagination Class twice?
Alot of your code is being over-written because of loading the Pagination Class the second time!
Remove the second load of the Pagination Class.

Also your missing a config item:
Code:
// controller/function/segment
$config['uri_segment'] = 3;

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB