title: PHP/Ajax load more button
body: <p>I want to display 5 items and when the user clicks the 'load more' button, 5 more items will be pulled out from the database.</p>
  
  <p>I have my items being retrieved like so:</p>
  
  <pre><code>$res = mysql_query("SELECT * FROM `posts` ORDER BY `id` DESC LIMIT 5") or die(mysql_error());
  
      if(mysql_num_rows($res) &gt; 0){
          while($row = mysql_fetch_assoc($res)){
              $id = $row['id'];
              $user_id = $row['user_id'];
  </code></pre>
  
  <p>then i have the ajax code and the button:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          $(".load_more").click(function (){
              $('.load_more').html('&lt;img src="images/ajax-loader.gif" /&gt;');
              $.ajax({
                  url: "loadmore.php?lastid=" + ("&lt;?php echo $id; ?&gt;"),
                  success: function(html){
                      if(html){
                          $(".main_page").append(html);
                          $('.load_more').html('Load More');
                      }else{
                          $('.load_more').replaceWith('&lt;center&gt;No more posts to show.&lt;/center&gt;');
                      }
                  }
              });
          });
      });
  &lt;/script&gt;
  
  
  
      &lt;button class="load_more"&gt;Load More&lt;/button&gt;
  </code></pre>
  
  <p>And finally the loadmore.php file that is being called when the button is clicked:</p>
  
  <pre><code>    $res17 = mysql_query("SELECT * FROM `posts` WHERE id &lt; '".addslashes($_GET['lastid'])."' LIMIT 0, 25 LIMIT 10"); 
  while($row17 = mysql_fetch_assoc($res17)){
              $id = $row17['id'];
              $user_id = $row17['user_id'];
  </code></pre>
  
  <p>how do i call the correct id? i know that
    url: "loadmore.php?lastid=" + (""), is probably wrong but not sure how to fix it</p>