title: Codeigniter Pagination Infinite Scroll Using Ajax And Jquery giving only Duplicate data
body: <p>I want to create pagination page into infinite scroll. I'm using codeigniter. But it is duplicating the data. So please help me to edit my pagination code. I had struggle for days. I will be so grateful if you can help me. Thank you.
  When I use the below code </p>
  
  <pre><code>$(window).scrollTop() + $(window).height() == $(document).height()
  </code></pre>
  
  <p>Its working fine</p>
  
  <p>And when I try to load when scroller reaches the <code>footer</code> div it gives only duplicate data.</p>
  
  <pre><code>$(window).scrollTop()+$(window).height() &gt;= $('#footerdivid').offset().top
  </code></pre>
  
  <p>My code is given below</p>
  
  <p>View</p>
  
  <pre><code>&lt;html&gt;
      &lt;body&gt;
          &lt;div id="container"&gt;
              &lt;h1&gt;Codeigniter Pagination Infinite Scroll&lt;/h1&gt;
              &lt;div id="body"&gt;
                &lt;ol&gt; &lt;div id="results"&gt;&lt;/div&gt;&lt;/ol&gt;
              &lt;/div&gt;    
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  
  &lt;script src="//code.jquery.com/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
  var total_record = 0;
  var total_groups = &lt;?php echo $total_data; ?&gt;;  
  $('#results').load("&lt;?php echo base_url() ?&gt;content/load_more",
   {'group_no':total_record}, function() {total_record++;});
  $(window).scroll(function() {       
      if($(window).scrollTop()+$(window).height() &gt;= $('#fooerdivid').offset().top)  
      {           
          if(total_record &lt;= total_groups)
          {
            loading = true; 
            $('.loader_image').show(); 
            $.post('&lt;?php echo site_url() ?&gt;content/load_more',{'group_no': total_record},
              function(data){ 
                  if (data != "") {                               
                      $("#results").append(data);                 
                      $('.loader_image').hide();                  
                      total_record++;
                  }
              });     
          }
      }
  });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');
  class Content extends CI_Controller {
      public function __construct()
      {
          parent::__construct();
          $this -&gt; load-&gt;model('content_model');
      }
  
      public function index()
      {
          $total_data = $this-&gt;content_model-&gt;get_all_count();
          $content_per_page = 5; 
          $this-&gt;data['total_data'] = ceil($total_data-&gt;tol_records/$content_per_page);
          $this-&gt;load-&gt;view('content_page', $this-&gt;data, FALSE);
      }
  
      public function load_more()
      {
          $group_no = $this-&gt;input-&gt;post('group_no');
          $content_per_page = 5;
          $start = ceil($group_no * $content_per_page);
          $all_content = $this-&gt;content_model-&gt;get_all_content($start,$content_per_page);
          if(isset($all_content) &amp;&amp; is_array($all_content) &amp;&amp; count($all_content)) : 
              foreach ($all_content as $key =&gt; $content) :
                   echo '&lt;li&gt;'.$content-&gt;title.'&lt;/li&gt;';
                   echo '&lt;p&gt;'.$content-&gt;description.'&lt;/p&gt;';                 
              endforeach;                                
          endif; 
      }
  
  }
  </code></pre>
  
  <p>Model</p>
  
  <pre><code>&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  
  class Content_model extends CI_Model
  {
      public function get_all_count()
      {
          $sql = "SELECT COUNT(*) as tol_records FROM content_information";       
          $result = $this-&gt;db-&gt;query($sql)-&gt;row();
          return $result;
      }
  
      public function get_all_content($start,$content_per_page)
      {
          $sql = "SELECT * FROM  content_information LIMIT $start,$content_per_page";       
          $result = $this-&gt;db-&gt;query($sql)-&gt;result();
          return $result;
      }
  
  }
  </code></pre>