JohnOP Posted April 21, 2012 Share Posted April 21, 2012 I am trying to code a php, mysql and jquery pagination much like the way twitter's pagination works. Page 1 i have <div id="load_more"> <?php $query = mysql_query("SELECT * FROM comments ORDER BY id DESC LIMIT 5"); while($row = mysql_fetch_assoc($query)){ $id = $row['id']; // show comments code } ?> </div> <script type="text/javascript"> $(function() { $('.showmore').live("click",function() { var ID = $(this).attr("id"); if(ID) { $("#more"+ID).html('<img src="ajax-loader.gif" />'); $.ajax({ type: "POST", url: "comments_more.php", data: "lastmsg="+ ID, cache: false, success: function(html){ $("#load_more").append(html); $("#more"+ID).remove(); // removing old more button } }); } else { $(".morebox").html('No more comments.');// no results } return false; }); }); </script> <div id="more<?php echo $id; ?>" class="morebox"> <a href="javascript:;" style="text-decoration: none; font-size: 12px; color: #ffffff; font-weight: bold; " class="showmore" id="<?php echo $id; ?>">Load More Comments</a> </div> So i am only showing 5 rows untill the link is clicked and then i want it to load more comments from comments_more.php which is the same page as above just it checks for the lastmsg id and alters the query to WHERE id < '$lastmsg'. Everything works ok for clicking the link and showing more results but it only works once. even if there is more than 10 rows it will show as "no more comments" after 10. Any help will be appreciated thanks. Quote Link to comment https://forums.phpfreaks.com/topic/261377-pagination-help/ Share on other sites More sharing options...
QuickOldCar Posted April 21, 2012 Share Posted April 21, 2012 Have a look at this pagination tutorial and try to integrate it. http://www.phpfreaks.com/tutorial/basic-pagination You are only ever going to get 5 results because you LIMIT them to 5 in the query need the pagination above and limits would be LIMIT $offset, $rowsperpage, the page numbers would then designate where the startrow/offset is and how many rows per page to display Quote Link to comment https://forums.phpfreaks.com/topic/261377-pagination-help/#findComment-1339386 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.