2017-06-15 35 views
0

我不是專家程序員。所以請好心幫助我。提前感謝。 正在嘗試從表中加載數據庫值,但是當運行程序數據時無限滾動,並且一次又一次地複製數據。 當表數據到達結尾時,我需要停止滾動。不需要複製數據。 `如何在數據庫值達到最終時停止無限滾動?

<?php 
include('connect.php'); 
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p']; 
# sql query 
$sql = "SELECT * FROM job_posting"; 
# find out query stat point 
$start = ($page * $limit) - $limit; 
# query for page navigation 
if(mysql_num_rows(mysql_query($sql)) > ($page * $limit)){ 
    $next = ++$page; 
    $hy=mysql_num_rows(mysql_query($sql)); 
    $limit=$hy; 
} 
$query = mysql_query($sql . " LIMIT {$start}, {$limit}"); 
if (mysql_num_rows($query) < 1) { 
    header('HTTP/1.0 404 Not Found'); 
    echo 'Page not found!'; 
    exit(); 
} 
?> 
<!doctype html> 
<html lang="en"> 
<head> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script type="text/javascript" src="js/jquery-ias.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 
    // Infinite Ajax Scroll configuration 
    jQuery.ias({ 
     container : '.wrap', // main container where data goes to append 
     item: '.item', // single items 
     pagination: '.nav', // page navigation 
     next: '.nav a', // next page selector 
     loader: '<img src="css/ajaxloader.gif"/>', // loading gif 
     triggerPageThreshold: 3 // show load more if scroll more than this 
    }); 
    }); 
</script> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>jQuery Load While Scroll</title> 
</head> 
<body> 
<div class="wrap"> 
    <h1><a href="#">Data load while scroll</a></h1> 

    <!-- loop row data --> 
    <?php while ($row = mysql_fetch_array($query)): ?> 
    <div class="item" id="item-<?php echo $row['j_id']?>"> 
    <h2> 
     <span class="num"><?php echo $row['id']?></span> 
     <span class="name"><?php echo $row['title'].' '.$row['jobtype']?></span> 
    </h2> 
    <p><?php echo $row['comp_name']?></p> 
    </div> 
    <?php endwhile?> 

    <!--page navigation--> 
    <?php if (isset($next)): ?> 
    <div class="nav"> 
    <a href='again.php?p=<?php echo $next?>'>Next</a> 
    </div> 
    <?php endif?> 
</div><!--.wrap--> 
</body> 
</html> 
+0

爲什麼java的標籤? –

+0

對不起...對不對...... – Anna

回答

0

您正在設置表中記錄數的限制。

$hy=mysql_num_rows(mysql_query($sql)); 
    $limit=$hy; 

上面的代碼 評論,並設置$限制任何數量開始像

$limit = 100; 
+0

對不起...不起作用 – Anna

+0

分享更新的代碼。你是否在$ start變量之前聲明瞭$ limit變量? –

+0

#查詢查詢統計點 $ limit = 100; $ start =($ page * $ limit) - $ limit; – Anna