我们在postgres中有一个表,该表具有10,000个值。每个值对应一个字符串。现在,我不想一次加载所有这些值,因为当表中的元组数增加时,可能要花费很多时间。所以我想我能做的就是一次加载说50个值。值从9,999-0开始。我用它作为我的代码:-
<head>
<form><input type="hidden" id="hiddencontainer" name="hiddencontainer" value="1000" />
<script language="JavaScript">
var wrapper, content, test, myhidden;
myhidden = document.getElementById("hiddencontainer");
var more = '<div style="height:100%; background:#e6f2ff;"><?php
$minId=$_REQUEST['hiddencontainer'];
$queryPost="select *
from userpostdec
where postid<".$minId." limit 50;";
$rows=pg_query($queryPost);
while($row=pg_fetch_array($rows)){
echo $row['content'];?><br><?php
}
?></div>';
// this is the scroll event handler
function scroller(){
if(wrapper.scrollTop + wrapper.offsetHeight + 1000 > content.offsetHeight){
content.innerHTML += more;
myhidden.value -= 50;
}
}
</script>
</form>
</head>
<script language="JavaScript">
wrapper = document.getElementById("wrapper");
content = document.getElementById("content");
test = document.getElementById("test");
//myhidden = document.getElementById("hiddencontainer");
myhidden.value=1000;
// hook the scroll handler to scroll event
if(wrapper.addEventListener)
wrapper.addEventListener("scroll",scroller,false);
else if(wrapper.attachEvent)
wrapper.attachEvent("onscroll",scroller);
</script>
因此,当用户“看到”所有的50个值时,我将加载下一个50个值。但是它似乎不起作用,我不明白为什么。请帮助我的代码。谢谢!