Codeigniter php activerecord orm limit and offset

Posted by user2167174 on Stack Overflow See other posts from Stack Overflow or by user2167174
Published on 2014-05-27T15:21:27Z Indexed on 2014/05/27 15:25 UTC
Read the original article Hit count: 269

Filed under:
|
|
|
|

I am a bit stuck with this problem I have in phpactiverecord. What I am trying to do is a pagination so I need to limit and offset the query results. I am accessing all of the user posts like so: $user->post; How can I query this to limit and offset the results? Thanx in advance.

Code:

public function office()
{
    if (!$this->session->userdata('username')) {
        redirect(base_url());
    }

    $data = array();
    $data['posts'] = [];
    $user = User::find('first', array('id' => $this->session->userdata('id')));
    if ($user != null) {

        if ($user->post != null) {

            foreach ($user->post as $post) {
                $posts = array($post->name, $post->description, $post->date,'<a href="'.base_url().'Posts/edit/'.$post->id.'">Edit</a> <br /><a href="'.base_url().'Posts/delete/'.$post->id.'">Delete</a>');
                array_push($data['posts'], $posts);
            }
            $this->table->set_heading('Name', 'Description', 'Date', '<a href="'.base_url().'Posts/create">+Add</a>');
            $tmpl = array('table_open' => '<table class="table table-stripped table-bordered user-posts">');
            $this->table->set_template($tmpl);
            $data['table'] = $this->table->generate($data['posts']);

        }
        $this->load->view('template/header.php');
        $this->load->view('Users/office.php', $data);
        $this->load->view('template/footer.php');


    } else {
        redirect(base_url());
    }


}

© Stack Overflow or respective owner

Related posts about php

Related posts about activerecord