title: Stop infinite scroll from repeating all page content
body: <p>I added infinite scroll to a page and now the page duplicates content from the top of the page each time more results load for the infinite scroll.</p>
  
  <p>The page loads like this:</p>
  
  <ul>
  <li>Advertisement</li>
  <li>Sponsored content</li>
  <li>Advertisement</li>
  <li>First 9 Results from table for infinite scroll</li>
  </ul>
  
  <p>When the page reaches the end for infinite scroll this happens </p>
  
  <ul>
  <li>Advertisement repats</li>
  <li>sponsored content repeats</li>
  <li>advertisement repeats</li>
  <li>next 9 rows from table shows as desired.</li>
  </ul>
  
  <p>I want to know how I can stop the Advertisements and sponsored content from repeating with my infinite scroll.</p>
  
  <p>here is the script i am using for the infinite scroll:</p>
  
  <pre><code>//      Loading news
      var pageLoad = 1;
      var totalPages = 1;
      /* This is function which is called to load news. The input parameter is page, a variable which assumes number of active page. Default is 1 */
      function loadingNews(page){
          $('#events').append('&lt;div class="loader-div"&gt;&lt;img src="" class="img img-responsive img-loader" /&gt;&lt;/div&gt;');
          $.ajax({
                 type: "GET",
                 url: "websitephppagebelow.php",
                 method: "POST",
                 dataType: "json",
                 data: {'eventuser': '0', 'page': page},
                 success: function (data) {
                 $(".loader-div").remove('.loader-div');
                 $('#events').append(data.deals);
                 totalPages = data.totalPages;
                 },
                 error: function (jqXHR, exception) {
                 var msg = '';
                 if (jqXHR.status === 0) {
                 msg = 'Not connect.\n Verify Network.';
                 } else if (jqXHR.status == 404) {
                 msg = 'Requested page not found. [404]';
                 } else if (jqXHR.status == 500) {
                 msg = 'Internal Server Error [500].';
                 } else if (exception === 'parsererror') {
                 msg = 'Requested JSON parse failed.';
                 } else if (exception === 'timeout') {
                 msg = 'Time out error.';
                 } else if (exception === 'abort') {
                 msg = 'Ajax request aborted.';
                 } else {
                 msg = 'Uncaught Error.\n' + jqXHR.responseText;
                 }
                 console.log(jqXHR);
                 }
                 });
      }
  
      /* Here the function for page loading is calling. The input parameter (pageLoad) is variable which constantly is updating. */
      loadingNews(pageLoad);
      /* This is the function which "listen" scrolling on the page. If it reaches the bottom of the page, sends new call to loadingNews function. */
      var win = $(window);
      win.scroll(function(){
                 if ($(document).height() - win.height() == win.scrollTop()) {
                 pageLoad++;
                 // console.log("page load: " + pageLoad + "; total: " + totalPages);
                 if(pageLoad &lt;= totalPages) {
                 loadingNews(pageLoad);
                 }else{
                 pageLoad--;
                 }
                 }
                 });
  
                 });
  </code></pre>
  
  <p>here is the php I am using for my infinite scroll:</p>
  
  <pre><code>&lt;?php
  include('../db.php');
  
  $event = '';
  
  
      if(isset($_REQUEST['myevents'])) {
  
  if(!isset($_REQUEST['eventuser']) || (strlen($_REQUEST['eventuser']) &lt; 2)) {
  
  $get = mysql_query("SELECT * FROM table ORDER BY stdate ASC");
  
  } else {
  
  $get = mysql_query("SELECT * FROM table WHERE user = '".$_REQUEST['eventuser']."' ORDER BY stdate ASC ");
  
  }
  if(mysql_num_rows($get) &gt; 0) {
  
      while($row = mysql_fetch_array($get)) {
      //echo mysql_num_rows($get).$row['id'].$row['name'].$row['stdate'].$row['description'].$row['fname'];
  
  
      $desc = substr($row['description'],0,50);
  
      $event .= '     &lt;div id="eventslist" onclick="goevent('.$row['id'].');" style="border-bottom:1px solid gray;padding:2px;width:100%;float:left;"&gt;
                          &lt;div style="width:35%;float:left;"&gt;
                              &lt;img src="path" style="width:100%;height:140px;border-radius:10px;" class="img-rounded"&gt;
                          &lt;/div&gt;
                          &lt;div style="width:65%;float:left;"&gt;
                              &lt;h4 style="margin:0;"&gt;&lt;span style="float:left;"&gt;'.$row['fname'].'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style="float:left;text-align:right;font-size:12px;"&gt;Start Date: '.$row['stdate'].'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br/&gt;&lt;span style="float:left;text-align:right;font-size:12px;"&gt;End Date: '.$row['endate'].'&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br/&gt;&lt;span style="float:left;text-align:right;font-size:12px;"&gt;City: '.$row['city'].'&lt;/span&gt;&lt;/h4&gt;&lt;p style="margin-bottom:0;"&gt;'.substr($row['description'],0,56).'...&lt;/p&gt;
                          &lt;/div&gt;
                  &lt;/div&gt;  ';
  
      }
      //echo $event."&lt;br/&gt;";
  
      $arr['status']=1;
      $arr['msg'] = 'ok';
      $arr['deals'] = $event;
  
  } else {
      $event .= 'No Events Found '.mysql_error();
      $arr['status']=0;
      $arr['msg'] = $event;
      $arr['deals'] = $event;
  }
  
  
      } else {
  
  if(!isset($_REQUEST['eventuser']) || (strlen($_REQUEST['eventuser']) &lt; 2)) {
  
  $get = mysql_query("SELECT * FROM table2 WHERE fname='mobile' ORDER BY RAND() LIMIT 1");
  
  } else {
  
  $get = mysql_query("SELECT * FROM table2 WHERE user = '".$_REQUEST['eventuser']."' ORDER BY stdate ASC");
  
  }
      if(mysql_num_rows($get) &gt; 0) {
  
      while($row = mysql_fetch_array($get)) {
      //echo mysql_num_rows($get).$row['id'].$row['name'].$row['stdate'].$row['description'].$row['fname'];
  
  
      $desc = substr($row['description'],0,50);
  
      $event .= '     &lt;div style="float:left" class="movead"&gt; 
                                          &lt;p style="margin-left:5%; color:black;text-align: left;width:100%;height:15px"&gt;&lt;b&gt;Advertisment&lt;/b&gt;&lt;/p&gt;
                                          &lt;a href="'.$row['link'].'" target="_blank" style="text-decoration: none;"&gt;
                                          &lt;div style="margin-left:2%;margin-bottom: 25px;width: 320px; height: 50px; background-image: url(path'); color: #fff; line-height: 50px; text-align: center; "&gt;
                                          &lt;/div&gt;
                                          &lt;/a&gt;
                                      &lt;/div&gt;  ';
  
  
      }
      //echo $event."&lt;br/&gt;";
  
      $arr['status']=1;
      $arr['msg'] = 'ok';
      $arr['deals'] = $event;
  
  } else {
      $event .= 'No Events Found '.mysql_error();
      $arr['status']=0;
      $arr['msg'] = $event;
      $arr['deals'] = $event;
  }
  
  
  if(!isset($_REQUEST['eventuser']) || (strlen($_REQUEST['eventuser']) &lt; 2)) {
  
  $get = mysql_query("SELECT * FROM table WHERE promote='YES' ORDER BY RAND() LIMIT 3");
  
  } else {
  
  $get = mysql_query("SELECT * FROM table WHERE user = '".$_REQUEST['eventuser']."' ORDER BY stdate ASC ");
  
  }
  if(mysql_num_rows($get) &gt; 0) {
  
      while($row = mysql_fetch_array($get)) {
      //echo mysql_num_rows($get).$row['id'].$row['name'].$row['stdate'].$row['description'].$row['fname'];
  
  
  
      $desc = substr($row['description'],0,50);
  
      $event .= '     &lt;div id="eventslist" class="zoom" onclick="goevent('.$row['id'].');" style="background-image: url(path);background-position: center;background-position-y: -1px;background-repeat: no-repeat;background-size: 100% 98%;box-shadow: 0 -2px 18px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);border-radius: 25px 25px 0 0;padding:2px;width:103%;margin-left:-1.6%;margin-bottom: 25px;float:left;"&gt;
  
                          &lt;div style="height:25px;width:101.08%;float:left;text-align: center;background-color: gold;margin-left:-.5%;margin-top:-.8%;border-radius: 25px 25px 0 0;"&gt;
                                                              &lt;b style="font-size: 16px;"&gt;Sponsored&lt;/b&gt;
                          &lt;/div&gt;
                          &lt;div style="width:101.19%;float:left;background-color: white;margin-left:-.65%;margin-top:60%;"&gt;
                                                              &lt;div style="float:left;width:100%;text-align: center;padding-bottom: 5px;padding-top: 5px;"&gt;
                                                              &lt;b style="font-size: 16px;"&gt;'.$row['fname'].'&lt;/b&gt;
                                                              &lt;/div&gt;
                                                              &lt;div&gt;
                              &lt;img src="path" style="margin-top:-1%;margin-left:2%;float:left;width:20px;height:20px;"&gt;&lt;b&gt;&lt;span style="margin-left:-2%;float:left;text-align:left;font-size:12px;padding-left: 10px;"&gt;Start Date: '.$row['stdate'].'&lt;/span&gt;&lt;span style="float:right;text-align:right;font-size:12px;padding-right: 10px;"&gt;City: '.$row['city'].'&lt;/span&gt;&lt;img src="path" style="margin-top:-1%;float:right;width:20px;height:20px;"&gt;&lt;/b&gt;
                                                              &lt;/div&gt;
                                                              &lt;div&gt;
                              &lt;p style="float:left;margin-bottom:0;padding:10px;"&gt;'.substr($row['description'],0,160).'...&lt;/p&gt; 
                                                              &lt;/div&gt;
                          &lt;/div&gt;
                  &lt;/div&gt;  ';
  
  
      }
      //echo $event."&lt;br/&gt;";
  
      $arr['status']=1;
      $arr['msg'] = 'ok';
      $arr['deals'] = $event;
  
  } else {
      $event .= 'No Events Found '.mysql_error();
      $arr['status']=0;
      $arr['msg'] = $event;
      $arr['deals'] = $event;
  }
  
  
      }
  
  if(!isset($_REQUEST['eventuser']) || (strlen($_REQUEST['eventuser']) &lt; 2)) {
  
  $get = mysql_query("SELECT * FROM table2 WHERE fname='mobile' ORDER BY RAND() LIMIT 1");
  
  } else {
  
  $get = mysql_query("SELECT * FROM table2 WHERE user = '".$_REQUEST['eventuser']."' ORDER BY stdate ASC");
  
  }
  if(mysql_num_rows($get) &gt; 0) {
  
      while($row = mysql_fetch_array($get)) {
      //echo mysql_num_rows($get).$row['id'].$row['name'].$row['stdate'].$row['description'].$row['fname'];
  
  
      $desc = substr($row['description'],0,50);
  
      $event .= '     &lt;div style="float:left" class="movead"&gt; 
                                          &lt;p style="margin-left:5%; color:black;text-align: left;width:100%;height:15px"&gt;&lt;b&gt;Advertisment&lt;/b&gt;&lt;/p&gt;
                                          &lt;a href="'.$row['link'].'" target="_blank" style="text-decoration: none;"&gt;
                                          &lt;div style="margin-left:2%;margin-bottom: 25px;width: 320px; height: 50px; background-image: url(path); color: #fff; line-height: 50px; text-align: center; "&gt;
                                          &lt;/div&gt;
                                          &lt;/a&gt;
                                      &lt;/div&gt;  ';
  
  
      }
      //echo $event."&lt;br/&gt;";
  
      $arr['status']=1;
      $arr['msg'] = 'ok';
      $arr['deals'] = $event;
  
  } else {
      $event .= 'No Events Found '.mysql_error();
      $arr['status']=0;
      $arr['msg'] = $event;
      $arr['deals'] = $event;
  }
  
  
  
  $numberRecords = 9;
  $page = 1;
  $limitLower = 3;
  $limitUpper = 9;
  $loadHtmlRes = '';
  
  $page = $_REQUEST['page'];
  $limitLower = ($page-1)*$numberRecords;
  $limitUpper = $page*$numberRecords;
  $allNewsQuery = mysql_query("select * from table");
  $totalPages = ceil(mysql_num_rows($allNewsQuery)/9);
  
  if(!isset($_REQUEST['eventuser']) || (strlen($_REQUEST['eventuser']) &lt; 2)) {
  
  $get = mysql_query("SELECT * FROM table ORDER BY stdate ASC LIMIT ".$limitLower.", 9");
  
  }
  if(mysql_num_rows($get) &gt; 0) {
  
      while($row = mysql_fetch_array($get)) {
      //echo mysql_num_rows($get).$row['id'].$row['name'].$row['stdate'].$row['description'].$row['fname'];
  
          $getf = mysql_query("SELECT * FROM private WHERE eventid = '".$row['id']."' AND state = 'NY'");
          if(mysql_num_rows($getf) &gt; 0) { } else {
  
  
      $desc = substr($row['description'],0,50);
  
      $event .= '     &lt;div id="eventslist" class="zoom" onclick="goevent('.$row['id'].');" style="background-image: url(path');background-position: center;background-position-y: -1px;background-repeat: no-repeat;background-size: 100% 98%;box-shadow: 0 -2px 18px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.2);border-radius: 16px 16px 0 0;padding:2px;width:103%;margin-left:-1.6%;margin-bottom: 25px;float:left;"&gt;
  
  
                          &lt;div style="width:101.19%;float:left;background-color: white;margin-left:-.65%;margin-top:60%;"&gt;
                                                              &lt;div style="float:left;width:100%;text-align: center;padding-bottom: 5px;padding-top: 5px;"&gt;
                                                              &lt;b style="font-size: 16px;"&gt;'.$row['fname'].'&lt;/b&gt;
                                                              &lt;/div&gt;
                                                              &lt;div&gt;
                              &lt;img src="path" style="margin-top:-1%;margin-left:2%;float:left;width:20px;height:20px;"&gt;&lt;b&gt;&lt;span style="margin-left:-2%;float:left;text-align:left;font-size:12px;padding-left: 10px;"&gt;Start Date: '.$row['stdate'].'&lt;/span&gt;&lt;span style="float:right;text-align:right;font-size:12px;padding-right: 10px;"&gt;City: '.$row['city'].'&lt;/span&gt;&lt;img src="path" style="margin-top:-1%;float:right;width:20px;height:20px;"&gt;&lt;/b&gt;
                                                              &lt;/div&gt;
                                                              &lt;div&gt;
                              &lt;p style="float:left;margin-bottom:0;padding:10px;"&gt;'.substr($row['description'],0,160).'...&lt;/p&gt; 
                                                              &lt;/div&gt;
                          &lt;/div&gt;
                  &lt;/div&gt;  ';
  
          }       
      }
      //echo $event."&lt;br/&gt;";
  
      $arr['status']=1;
      $arr['msg'] = 'ok';
      $arr['deals'] = $event;
      $arr['totalPages'] = $totalPages;
  
  } else {
      $event .= 'No Events Found '.mysql_error();
      $arr['status']=0;
      $arr['msg'] = $event;
      $arr['deals'] = $event;
  }
  
  
  
  echo json_encode($arr);
  
  ?&gt;
  </code></pre>