2014-01-30 62 views
0

我正在使用無限ajax滾動。來自數據庫的值被正確提取。但是當我向下滾動時,顯示從0到10的相同結果。我不知道我犯了什麼錯誤。無限ajax滾動,php和jquery

查詢打印在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

您的查詢總是選擇前10個結果 #sql查詢 $ 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); – spezzino

+0

是的。如何讓它選擇下十個結果 – user2959949

+0

看看答案,什麼值有$ limit變量? – spezzino

回答

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); 
+0

謝謝你現在的工作 – user2959949

2

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

將其更改爲;

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

我已經犯了一些錯誤,在循環中增加下一個結果後,十個沒有得到我的數據庫中有72個結果,前十個重複顯示。我需要它來使dyanmic – user2959949

+0

我已作出更改,因爲你說http://tamil.kornerseat.com/news1.php仍然是相同的結果 – user2959949