簡體   English   中英

無限的ajax滾動,php和jquery

[英]Infinite ajax scroll, php and jquery

我正在使用無限的ajax滾動。 正確獲取數據庫中的值。 但是當我向下滾動時,會顯示從0到10的相同結果。 我不知道我犯了什么錯誤。

查詢將打印在此鏈接中 如何通過遞增下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')?>

mysql_real_escape_string($category), 0, 10); 是你的問題。

把它換成;

mysql_real_escape_string($category), $start, 10);

您需要設置$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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM