Welcome Guest, Not a member yet? Register   Sign In
Messing with pagination all day and I'm almost there.
#1

[eluser]internut[/eluser]
This is probably very ugly but it seems to be working well thus far. Still have a few things to add.

Its doing pagination, sorting (keeping track of sort during page changes via cookie).

Any thoughts?

Code:
// Here we go with pagination

        $data[user_count] =  $this->db->count_all('users');

        if(get_cookie('user_sort')) {
            $sort = get_cookie('user_sort');
        }


        if($this->uri->segment(4)) {
          $sort = $this->uri->segment(4);
          setcookie("user_sort", $sort);
        };

        if(!$sort) {             $sort = "last_name";         }

        if($this->uri->segment(3))    {  $start = $this->uri->segment(3) ;  }
        if(!$start)                   {  $start = 0;  }

        $this->load->library('pagination');

        $config['base_url'] = site_url() . "/users/page/";
        $config['total_rows'] = $data[user_count];
        $config['per_page'] = '5';
        $config['uri_segment'] = 3;
        $config['num_links'] = 5;


        $data['query'] = $this->db->query("SELECT * FROM users ORDER BY $sort ASC LIMIT $start,$config[per_page]");     // query time

        $this->pagination->initialize($config);
        $data[pages] =  $this->pagination->create_links();

        $data[sys_message] = $this->session->flashdata('sys_message');  // set system message to display

     $this->load->view('users_view',$data);
#2

[eluser]internut[/eluser]
almost there - goda throw a search field into the mix. Like to get some feed back if i'm going about things correctly in the long run.
#3

[eluser]SeanJA[/eluser]
Ah, thats a lot more clever than mine was... mostly because I wrote my own pagination system...
#4

[eluser]internut[/eluser]
Its a lot more code now.

I have put in search, sorting, keeps you on the same page while sorting, drop down select option for an ENUM mysql table field to only show & search certain records (active/inactive/approve/canceled).

I think I almost done!




Theme © iAndrew 2016 - Forum software by © MyBB