1

I am new to Codeigniter. I am applying infinite scrolling. I am getting reference from Infinite scroll. I want to work it with database records. But it is not working.

Let me show Code:

In News Controller:

//Rendering view
    public function infiniteScroll() {
        $total_data = $this->news_model->get_all_count();
        $data['title'] = 'News List';

        $offset = 30; 
        $all_content = $this->news_model->get_all_content(0,$offset);
        $data['news'] = $all_content;
        $data['content'] = "news/scrollNews";
        $this->load->view('templates/main', $data,FALSE);
    }

// Load More data on page scroll
    public function loadMore($page=1, $count = 30)
    {
        $offset = ($page - 1)*$count;
        $data['title'] = 'News List';
        $all_content = $this->news_model->get_all_content($count,$offset);

        $data['news'] = $all_content;
        $data['content'] = "news/scrollNews";
        $this->load->view('templates/main', $data,FALSE);
    }

My view page:

<div id="posts">
    <?php foreach ($news as $nw){ ?>
    <div class="post">
        <?= $nw->log_id ?>
    </div>
  <?php } ?>
</div>

<div id="pagination">
    <a href="loadMore" class="next">next</a>
</div>

<script>
var ias = jQuery.ias({
  container:  '#posts',
  item:       '.post',
  pagination: '#pagination',
  next:       '.next',
});
</script>

Here my loadMore function is called on click but i can't get any parameter to set offset. I am new so i don't know how to get next records on click.

Also i need data to be loaded on scroll. Not in click.

Any help please.

Dhara
  • 1,242
  • 3
  • 22
  • 41

1 Answers1

0

when we click on next button it's getting the URL from "anchor href attribute"

change

<div id="pagination">
<a href="loadMore" class="next">next</a>

to

<div id="pagination">
            <a href="base_url/controller/action/$page" class="next-posts">next</a>
        </div>

I am not sure, but I think it's working for you

  • this will give me error for $page variable. and i also want that not to click on link. it should load data automatically on scroll. I don't understand why document is not properly informative in demo. – Dhara Jun 05 '17 at 11:51
  • Check this [solution in other answer](https://stackoverflow.com/questions/14934667/infinite-scroll-jquery-plugin-in-codeigniter) – elddenmedio Jun 05 '17 at 14:51