加载更多功能

Am retrieving posts from a database via ajax call and displaying them with jQuery and JSON, and i want to implement a load more feature, to allow users see more posts without refreshing the page. In my attempt at this i hard coded the offset in the the javascript function making the ajax request, so the function kept loading the same post continuously. this is the codeigniter controller

    function latest_pheeds($offset = 0) {
                //Confirm if a user is logged before allowing access
                if($this->isLogged() == true) {
                //Limit
                $limit = 20;
                //user id
                $user_id = $this->session->userdata('user_id');     
                //Load the date helper to calculate time difference between post time and current time
                $this->load->helper('date');
                //Current time(unix timetamp)
                $time = time();
                $pheeds = array();
                    $dt = $this->pheed_model->get_latest_pheeds($limit,$offset);
                    $data = $dt['pheeds'];
                    if($data != false && !empty($data)) {
//total no of pheeds
$total_rows = $dt['total']
                        foreach($data as $pheed) {
                            $row['pheed_id'] = $pheed->pheed_id;
                            $row['user_id'] = $this->user_model->return_username($pheed->user_id);
                            $row['pheed'] = $pheed->pheed;
                            $row['datetime'] = $pheed->datetime;
                            $row['comments'] = $this->comment_model->count_comments($pheed->pheed_id);
                            $row['repheeds'] = $pheed->repheeds;
                            if($this->user_model->is_owner($pheed->pheed_id,$user_id,'pheed'))
                            {
                                $row['owner'] = "yes";
                            }else {
                                $row['owner'] = "no";
                            }
                            if($pheed->avatar == 0)
                            {
                                $row['avatar_src'] = site_url().$this->site_config->get_setting_value('default_avatar_small');
                            }else {
                                $row['avatar_src'] = $pheed->avatar_small;
                            }
                            $pheeds[] = $row;
                        }
                        echo json_encode($pheeds);
                    }
                } else {
                    $this->output->set_status_header('401',"Attempting Unauthorized Access");
                }
            }

How would i determine to next offset to encode into the json array for pagination, as i have the total no of rows for the request

You can use a global javascript variable and store the count in there for each click of "load more". for each ajax call, sent the count to server as a query string. pass the count value as an argument to your function. Using that count value argument, you can query the database for "more posts".

By the way what does the "get_latest_pheeds" function does?