CodeIgniter Forums
paging problem Search form - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: paging problem Search form (/thread-18773.html)



paging problem Search form - El Forum - 05-18-2009

[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]



paging problem Search form - El Forum - 05-18-2009

[eluser]├╝berfuzz[/eluser]
Nice post dude! Is there something else? Confusedmirk:


paging problem Search form - El Forum - 05-18-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="├╝berfuzz" date="1242649997"]Nice post dude! Is there something else? Confusedmirk:[/quote]

lol.


paging problem Search form - El Forum - 05-18-2009

[eluser]Dam1an[/eluser]
I somehow saw the 2 replies first, and was wondering wtf... then I saw the post lol
Glad to see I'm not the only one wondering

(also, whats with the quotes inside the code block?)


paging problem Search form - El Forum - 05-19-2009

[eluser]JulianM[/eluser]
Did you solve your problem?

Just was wondering.


paging problem Search form - El Forum - 05-19-2009

[eluser]gvillavizar[/eluser]
[quote author="JulianM" date="1242774218"]Did you solve your problem?

Just was wondering.[/quote]

Well, he didn't explained the problem in the first place.


paging problem Search form - El Forum - 05-19-2009

[eluser]JulianM[/eluser]
Yes, basically that is why I asked :p

[quote author="gvillavizar" date="1242778083"][quote author="JulianM" date="1242774218"]Did you solve your problem?

Just was wondering.[/quote]

Well, he didn't explained the problem in the first place.[/quote]


paging problem Search form - El Forum - 05-19-2009

[eluser]maxfuchs[/eluser]
I was wondering is there anyone could help him?


paging problem Search form - El Forum - 05-19-2009

[eluser]maxfuchs[/eluser]
anyone could help him?
poor him lol


paging problem Search form - El Forum - 05-23-2009

[eluser]dine[/eluser]
My problem is somewhat similar to post.

I am writing a custom query and using
$this->db->query($Sql);

now I need to do paging.

i am wondering what I need to write as limit in searching query. I means...for example
$Sql = "select * from abc limit startindex,lastindex"
Just ignore the error,syntax..
There is no restriction to use POST or GET Method.

Kindly let me know if you need to ask anything else more to reslove this prob.

thanks in advance