php - Infinite scrolling jquery ajax -
i'm using jquery ,ajax , php implementing infinite scrolling image database
and code works 1 time when reach end of page , show me message "no more content" when there content in database
here cod
index.php
<html > <?php include($_server["document_root"].'/db.php'); $query = "select * photo order photono desc limit 12"; $result = mysql_query($query) or die('query failed: ' . mysql_error()); $actual_row_count =mysql_num_rows($result); ?> <head> <title>infinite scroll</title> <script src="jquery-1.7.2.js" type="text/javascript"></script> <script type="text/javascript"> var page = 1; $(window).scroll(function () { $('#more').hide(); $('#no-more').hide(); if($(window).scrolltop() + $(window).height() > $(document).height() - 200) { $('#more').css("top","400"); $('#more').show(); } if($(window).scrolltop() + $(window).height() == $(document).height()) { $('#more').hide(); $('#no-more').hide(); page++; var data = { page_num: page }; var actual_count = "<?php echo $actual_row_count; ?>"; if((page-1)* 12 > actual_count){ $('#no-more').css("top","400"); $('#no-more').show(); }else{ $.ajax({ type: "post", url: "data.php", data:data, success: function(res) { $("#result").append(res); console.log(res); } }); } } }); </script> </head> <body> <div id='more' >loading more content</div> <div id='no-more' >no more content</div> <div id='result'> <?php while ($row = mysql_fetch_array($result)) { $rest_logo=$row['photoname']; $image="../images/rest/".$rest_logo; echo '<div><img src='.$image.' /></div>'; } ?> </div> </body> </html>
data.php
<?php $requested_page = $_post['page_num']; $set_limit = (($requested_page - 1) * 12) . ",12"; include($_server["document_root"].'/db.php'); $result = mysql_query("select * photo order photono desc limit $set_limit"); $html = ''; while ($row = mysql_fetch_array($result)) { $rest_logo=$row['photoname']; $image="../images/rest/".$rest_logo; $html .= '<div><img src='.$image.' /></div>'; } echo $html; exit; ?>
i nead
you see setting variables wrong quick look:
var actual_count = "<?php echo $actual_row_count; ?>";
you're using mysql_num_rows() count return on first set of results. limited 12.
you need second mysql query images without limi, count them total number of images in database.
Comments
Post a Comment