bytesize Posted January 13, 2011 Share Posted January 13, 2011 Can someone please tell my why the 'more' link continues to load after reaching the last message in the database. It should stop and display 'The End' loadmore.php <?php include('db_connect.php'); ?> <script type="text/javascript" src="jquery-1.4.4.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.more').live("click",function() { var ID = $(this).attr("id"); if(ID) { $("#more"+ID).html('<img src="moreajax.gif" />'); $.ajax({ type: "POST", url: "ajax_more.php", data: "lastmsg="+ID, cache: false, success: function(html){ $("ol#updates").append(html); $("#more"+ID).remove(); } }); } else { $(".morebox").html('The End'); } return false; }); }); </script> </head> <body> <ol class="timeline" id="updates"> <?php $sql=mysql_query("SELECT * FROM messages ORDER BY msg_id DESC LIMIT 8"); while($row=mysql_fetch_array($sql)) { $msg_id=$row['msg_id']; $message=$row['message']; ?> <li> <?php echo $message; ?> </li> <?php } ?> </ol> <div id="more<?php echo $msg_id; ?>" class="morebox"> <a href="#" class="more" id="<?php echo $msg_id; ?>">more</a> </div> </body> </html> ajax_more.php <?php include("db_connect.php"); if(isset($_POST['lastmsg'])) { $lastmsg=$_POST['lastmsg']; $result=mysql_query("SELECT * FROM messages WHERE msg_id<'$lastmsg' ORDER BY msg_id DESC LIMIT 8"); $count=mysql_num_rows($result); while($row=mysql_fetch_array($result)) { $msg_id=$row['msg_id']; $message=$row['message']; ?> <li> <?php echo $message; ?> </li> <?php } ?> <div id="more<?php echo $msg_id; ?>" class="morebox"> <a href="#" id="<?php echo $msg_id; ?>" class="more">more</a> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/224353-keeps-refreshing-the-more-link/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.