Jump to content

Pagination help


JohnOP

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.