Welcome Guest, Not a member yet? Register   Sign In
Paginating a form
#1

[eluser]cpass78[/eluser]
Hello, my first post so please bare with me here.

I have been using CI for some weeks and building an app that is pretty extensive in nature but that i cannot go into to much detail on sadly, however I'll explain my issue.

I'm building out forms that are actually "surveys" with everything relating to the form except the HTML being pulled from the db. My issue is that these forms are required to display 5 questions per page so basically i need to:

query 5 rows in the db
display those results in the form
fill out those Q's
hit the next button
load the next 5 and repeat

I'm not sure how to properly set my offset in the url, or wherever to be able to know how to get the next results and how to know when there are less than 5 to change the next button to a submit button.

Sorry if i am vague but I'll be happy to answer any questions you have.

Thanks so much
#2

[eluser]cpass78[/eluser]
ok maybe posting some code would spike interest :p Here is my controller:

Code:
function survey($page = ''){
        $this->output->enable_profiler(TRUE);
        $this->benchmark->mark('code_start');
        
        //load the model and get results
        $this->load->model('board_member_model');
        //echo $this->limit;
        if ($this->input->post('next')){
            $this->data['page'] = $page+5; //I dont think this is correct, but it works sorta
        }else{
            $this->data['page'] = $page;
        }
        $this->data['survey'] = $this->board_member_model->getSurvey($this->limit, $page);
        $this->data['survey_question'] = $this->input->post('question');
        $this->data['survey_comment'] = $this->input->post('comment');
        $this->load->view('board_member', $this->data);
        
        $this->benchmark->mark('code_end');
        
    }

Calling method of Model:
Code:
function getSurvey($offset = '', $page = '') {
            //$this->db->select('survey_id, question_id, questions, answers, type');
            $this->db->from('#########');
            $this->db->join('#########', '#########.question_id = #########.question_id');
            $this->db->join('#########', '#########.question_id = #########.question_id');
            $this->db->limit($offset,$page);
            $query = $this->db->get();
            if ($query->num_rows() > 0) {
                return $query->result();
            }else{
                return "No Results Found";
            }
        }
And the view just spits all this out into a form that posts to
Code:
echo form_open('board_member/survey/'.$page);
where the url should pick up the offset, which does happen but because $page is incremented, when there are no more records it errors out..
#3

[eluser]cpass78[/eluser]
Anyone have any thoughts?
#4

[eluser]cpass78[/eluser]
Is this really difficult to accomplish? I know it is for myself but does no one on here have an opinion? I am here for help after all an di hear these forums are full of brilliant helpful people.
#5

[eluser]cpass78[/eluser]
Bump
#6

[eluser]cpass78[/eluser]
Unimpressed thus far with the interest to this topic...




Theme © iAndrew 2016 - Forum software by © MyBB