Welcome Guest, Not a member yet? Register   Sign In
paging problem Search form
#1

[eluser]xico[/eluser]
Code:
[quote]$data['siteTitle'] = 'My Test Project';
        $data['results'] = $this->usermodel->get_all();
        $data['totalRecords'] = $this->usermodel->countTotal();
        $data['pagingStr'] = $this->usermodel->paging($data['totalRecords']);
        if($data['totalRecords'] < 1) {
            $data['messageString'] = 'Sorry no records found!';
        } else {
            $data['messageString'] = '';
        }
        if (is_array($_GET) && (count($_GET) > 0))
        {
            $data['sn'] = floor((10 * $this->usermodel->page)+1);
        } else {
            $data['sn'] = 1;
        }
        $this->load->view('user_view',$data);

function get_all()
    {    
        if (is_array($_GET) && (count($_GET) > 0))
        {
            $this->page = $_GET['per_page'];

            foreach($_GET as $index => $value)
            {
                if($index != 'SortBy' && $index != 'OrderBy' && $index != 'Submit' && $index != 'c' && $index != 'per_page' && $value <> '')
                {
                    $this->db->where($index.' like "%'.$value.'%"');
                }
            }
        }
        
        //check query
        //$this->db->debug = true;
        
        $start = ($this->page * $this->limit);
        $this->db->orderby('Email','asc');
        $query = $this->db->get('users', $this->limit, $start);
        return $query->result();
    }

    function countTotal()
    {    
        if (is_array($_GET) && (count($_GET) > 0))
        {
            foreach($_GET as $index => $value)
            {
                if($index != 'SortBy' && $index != 'OrderBy' && $index != 'Submit' && $index != 'c' && $index != 'per_page' && $value <> '')
                {
                    $this->db->where($index.' like "%'.$value.'%"');
                }
            }
        }
        $query = $this->db->get('users');
        return $query->num_rows();
    }

    function paging($total = 0)
    {    
        $strURL = '';
        if (is_array($_GET) && (count($_GET) > 0))
        {
            foreach($_GET as $index => $value)
            {
                if($index <> 'per_page' && $index <> 'c' && $index <> 'm')
                {
                    $strURL .= '&'.$index.'='.$value;
                }
            }
        }

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

        $config['base_url'] = $this->config->config['base_url'].'user/index/?c=user'.$strURL;
        $config['total_rows'] = ceil($total/$this->limit);
        $config['per_page'] = '1';
        $config['num_links'] = 5;

        $this->pagination->initialize($config);

        return $this->pagination->create_links();

    }
[/quote]


Messages In This Thread
paging problem Search form - by El Forum - 05-18-2009, 12:16 AM
paging problem Search form - by El Forum - 05-18-2009, 01:33 AM
paging problem Search form - by El Forum - 05-18-2009, 01:43 AM
paging problem Search form - by El Forum - 05-18-2009, 02:01 AM
paging problem Search form - by El Forum - 05-19-2009, 12:03 PM
paging problem Search form - by El Forum - 05-19-2009, 01:08 PM
paging problem Search form - by El Forum - 05-19-2009, 01:28 PM
paging problem Search form - by El Forum - 05-19-2009, 01:58 PM
paging problem Search form - by El Forum - 05-19-2009, 01:59 PM
paging problem Search form - by El Forum - 05-23-2009, 07:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB