php - CodeIgniter Load More Comment Result

994

anyone can help me to make load more or doing pagenation for the comment result of the topic content?. This is how it it works my topic content call the query using the slug now I want the topic content reply show by pagenation or via load more button

My topic content controller:

 public function topic($slug = NULL) {

        // get single topic
        $data['item'] = $this->topic_model->getTopic($slug);
        if(empty($data['item'])) {
            $data['title'] = lang_key('404errorheader');
            $data['desc'] = lang_key('404errordesc');
            $this->load->view('themes/default/header', $data);
            $this->load->view('errors/html/error_404');
            $this->load->view('themes/default/footer');
        }else{ 

        $data['title'] = $data['item']['title'];
        $data['desc'] = strip_tags(word_limiter($data['item']['content'],30));

        $this->load->view('themes/default/header', $data);
        $this->load->view('threads/topic', $data);
        $this->load->view('themes/default/footer');
        $this->add_view($slug);
        }
    }

and my topic content model:

 // get single topic
    public function getTopic($slug) {
        $query = $this->db->get_where('threads', array('thread_slug'=>$slug));
        return $query->row_array();
    }

and my topic reply helper:

//get topic reply
if ( ! function_exists('get_topic_reply'))
{
    function get_topic_reply($topic_id)
    {

        $CI = get_instance();
        $CI->load->database();

        $CI->db->order_by('id', 'asc');
        $CI->db->where('topic_id',$topic_id);
        $CI->db->where('status',1);
        $query = $CI->db->get_where('threads_comment');
        return $query;

    }
}

This is how I display the result. mydomain/topic/topic-slug Content of the topic data is the topic content calling the query using slug and I only include the content reply via:

<?php require('topicreply.php');?>

The codes of this topicreply.php:

I want the result in topicreply.php will not display all instead there will be a load more button or pagenation. Anyone can help me? Ive been looking on the Internet but I cant find similar to my problem.

Note: The codes is working fine and no problem at all its only, I want the topic reply/comment can be view some of the reply via pagenation or loadmore!

487

Answer

Solution:

Its working now but instead of Load More I use pagination. Here the code in my controller

// category
  public function threadsview($slug=null, $offset=0) {
    // get threads category
    $this->load->helper('form');
    $this->load->library('form_validation');
    $this->load->library('pagination');

    $data['item'] = $this->threads_model->getThreadsCategory($slug);
    if($data['item']->num_rows()<=0){
      $data['title'] = lang_key('404errorheader');
      $data['desc'] = lang_key('404errordesc');
      $this->load->view('themes/default/layout/header', $data);
      $this->load->view('errors/html/error_404');
      $this->load->view('themes/default/layout/footer');
    }else
    foreach ($data['item']->result() as $res) {


    $data['title'] = $res->catname;
    $data['desc'] = $res->description;

    $cat_id = get_category_id_by_slug($slug);
    $total = 10; // total result x page

    // Config setup
    $num_rows = $this->threads_model->getAllThreadsPost($cat_id); // get all threads post per category
    $config['base_url'] = base_url().'threadsview/'.$slug;
    $config['total_rows'] = $num_rows;
    $config['per_page'] = $total;
    $config['num_links'] = $num_rows;
    $config['use_page_numbers'] = TRUE;
    $config['page_query_string'] = TRUE;
    $config['query_string_segment'] = 'page';
    $config['full_tag_open'] = '<ul >';
    $config['full_tag_close'] = '</ul>';
    $config['prev_link'] = '&laquo;';
    $config['prev_tag_open'] = '<li>';
    $config['prev_tag_close'] = '</li>';
    $config['next_tag_open'] = '<li>';
    $config['next_tag_close'] = '</li>';
    $config['cur_tag_open'] = '<li ><a href="#">';
    $config['cur_tag_close'] = '</a></li>';
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['next_link'] = '&raquo;';

    if ($this->input->get('page') != null) {
      $offset = ($this->input->get('page') - 1) * $config['per_page'];
    }

    $this->pagination->initialize($config);
    $data['threads_post'] = $this->threads_model->AllThreadsPost($cat_id, $config['per_page'], $offset);

    $this->load->view('themes/default/layout/header', $data);
    $this->load->view('threads/threadsview', $data);
    $this->load->view('themes/default/layout/footer');
    }
  }

But I have another concern I hope someone can help me. The result numbering is my problem. As you can see the pagination will display 10 results every page but my result numbering once you go to second page instead the number will goes to 11 to 20 it will return to 1-10. Look the codes below

<?php if(count($threads_post) > 0){ ?>
                                                <?php 
                                                $i = 0;
                                                foreach($threads_post as $threads): 
                                                $i++;?>

People are also looking for solutions to the problem: php - How we can get a div with HTML data in a JavaScript variable

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.