我有一个客户端需要输出数据库中ID引用的页面。页面必须一个接一个地输出(如幻灯片放映),并且必须有滑块过渡效果。为了使其“有趣”,数据库将随着新页面的添加而改变,因此必须重复运行执行所有这些操作的脚本的一部分以检查数据库。
我已经加载了页面,并且我已经完成了转换工作。问题是,我不能让投票工作,因为这样的混乱。也就是说,如果我添加一个新页面,我必须手动重新加载脚本 - 我需要脚本来检测添加到数据库的新页面。我知道我真正需要做的只是重新运行数据库查询以生成数组,但是随着所有其他事情的继续,我迷失了。我已经尝试了setInterval()甚至是一个while循环无济于事。在这一点上,我确信我只是遗漏了一些东西(希望是琐碎的),所以我谦卑地寻求帮助。在我测试时,我的代码非常草率,但这里是:
<?php
$community_id = 89;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
<?php
$con=mysqli_connect("localhost","username","password","db_name");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// get all the pages that pertain to the community
$uid_query = "SELECT uid FROM pages WHERE pid=" . $community_id;
// build the javascript array by grabbing all results from above query
$result = mysqli_query($con,$uid_query);
$counter = 0;
$baseURL = "http://www.website.com/index.php?id=";
echo "var frames = new Array;";
while($row = mysqli_fetch_array($result)) {
echo "frames[" . $counter . "]='" . $baseURL . $row['uid'] . "';";
$counter++;
echo "frames[" . $counter . "] = 5;";
$counter++;
}
mysqli_close($con);
?>
var i = 0, len = frames.length;
function ChangeSrc()
{
if (i >= len) { i = 0; } // start over
document.getElementById('frame').src = frames[i++];
setTimeout('ChangeSrc()', (frames[i++]*1000));
}
window.onload = ChangeSrc;
</script>
<style type="text/css">
body, html
{
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
#iframe_container
{
position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
}
</style>
</head>
<body>
<div id="iframe_container">
<iframe src="" name="frame" id="frame" width="100%" height="100%" frameborder="0"></iframe>
</div>
</body>
</html>
...然后任何给定的页面如下所示:
的javascript:
$(document).ready(function(){
$('.hidden').slideDown(1000);
});
的CSS:
.hidden{
display:none;
}
HTML:
<div class="hidden">
CONTENT GOES HERE
</div>