我正在使用无限的ajax滚动。正确获取数据库中的值。但是当我向下滚动时,会显示从0到10的相同结果。我不知道我犯了什么错误。
查询以this link打印。如何通过递增下10个结果来使查询动态化?目前,滚动时会显示相同的结果。
<?php include_once('../inc/header.php')?>
<?php
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
echo $page;
# find out query stat point
$start = (($page * $limit) - $limit);
# sql query
$SQL = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM review_news WHERE category='%s' ORDER BY id DESC LIMIT %d, %d",
mysql_real_escape_string($category), 0, 10);
print $SQL;
# query for dataset
$ResDataSet = mysql_query($SQL) or die(mysql_error());
# query for page navigation
$ResFoundRow = mysql_query("SELECT FOUND_ROWS() AS NumRow") or die( mysql_error() );
$RowFoundRow = mysql_fetch_array($ResFoundRow);
if ( $RowFoundRow['NumRow'] <= 0)
{
echo 'Page not found!';
exit();
} else if( $RowFoundRow['NumRow'] > ($page * $limit) ) {
$next = ++$page;
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery-ias.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Infinite Ajax Scroll configuration
jQuery.ias({
container : '#loop', // main container where data goes to append
item: '.review', // single items
pagination: '.nav', // page navigation
next: '.nav a', // next page selector
loader: '<img src="ajax-loader.gif"/>', // loading gif
triggerPageThreshold: 3 // show load more if scroll more than this
});
});
</script>
<style>
/*Loader style*/
.ias_loader, .ias_trigger {
text-align:center;
margin: 30px 0 40px;
}
.ias_trigger a:link,
.ias_trigger a:visited {
padding: 4px 50px;
background-color: #f9f9f9;
border: solid 1px #ddd;
border-radius: 2px;
font: bold 12px Arial, sans-serif;
color: #555;
text-decoration: none;
}
.ias_trigger a:hover,
.ias_trigger a:active {
border-color: #ccc;
}
</style>
<div class="content left" >
<!-- CONTENT AREA START -->
<div id="loop" class="list-view clear">
<h3><span>Recent News</span>
</h3>
<?php
while ($row = mysql_fetch_array($ResDataSet)){
?>
<div id="post_76" class="review type-review status-publish hentry post">
<div class="post-content">
<a class="post_img" href="review-default-news.php?id=<?php echo base64_encode($row['id']);?>"><img src="<?php
if($row['image_name']=="")
{
echo 'http://www.kornerseat.com/news/noimage.jpg';
}else{
?>http://www.kornerseat.com/news/<?php echo $row['image_name'];?> <?php }?>" alt="<?php echo $row['heading'];?>" title="<?php echo $row['heading'];?>" /> </a>
<div class="post_content">
<h2><a class="widget-title" href="review-default-news.php?id=<?php echo base64_encode($fetch_news['id']);?>"><?php echo $row['heading'];?></a></h2>
<div class="post_right">
<!--<a href="#" class="pcomments" >4 </a> -->
</div>
<p>
<?php
if(strlen($row['news'])<=65)
{
echo $row['news'];
}else{
$y=substr($row['news'],0,150) . '...';
echo $y;
}
?>
<a href="review-default-news.php?id=<?php echo base64_encode($row['id']);?>" class="read_more"> Read More </a></p>
</div>
</div>
</div>
<?php
}
?>
<?php if (isset($next)): ?>
<div class="nav">
<a href='news1.php?p=<?php echo $next?>'>Next</a>
</div>
<?php endif?>
</div>
<!-- CONTENT AREA END -->
</div>
<?php include_once('../inc/right.php')?>
<?php include_once('../inc/footer.php')?>
答案 0 :(得分:2)
mysql_real_escape_string($category), 0, 10);
是你的问题。
将其更改为;
mysql_real_escape_string($category), $start, 10);
答案 1 :(得分:0)
您需要设置$limit
以正确计算$start
,然后在查询中使用$start
和$limit
$limit = 10;
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
echo $page;
# find out query stat point
$start = (($page * $limit) - $limit);
# sql query
$SQL = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM review_news WHERE category='%s' ORDER BY id DESC LIMIT %d, %d",
mysql_real_escape_string($category), $start, $limit);