【发布时间】:2012-05-03 16:13:08
【问题描述】:
我有一个使用 Twitter API 存储 Twitter 帖子的数据库 - 在标题 id(存储为标签:search.twitter.com,2005:195795633834176512)下,作者,时间,文本 - 我有一个打印出来的页面该数据库中最近 7 天的帖子。 有时,最后 7 个帖子可能是 10-20 个帖子,有时可能是 100-200 个。 我一直在尝试将新闻自动收录器集成到页面中,因此每个帖子都出现在一个框中,然后淡出以被另一个帖子替换,这意味着您有一个迭代而不是 200 行:
<div id="news1">
<h3>Stackoverflow</h3>
<!-- Displaying News Module -->
<div class="news-container" style="overflow-x: hidden; overflow-y: hidden; position: relative; height: 1207px; ">
<!-- ul id="news-scroller" -->
<ul style="left: 207px; position: absolute; margin-top: 0px; margin-right: 0px; margin- bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; top: 0px; ">
<li style="display: list-item; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; height: 69px; ">
<div style="padding-bottom: 5px;">
<!-- Displaying News Module -->
<?php
require_once 'db-functions.inc.php' ; //custom database functions
echo "<ul class=\"twitter_feed\">\n" ;
$result = dbQuery("SELECT * FROM `HASH` WHERE text LIKE '%stackoverflow%' AND `hidden` != 'y' AND from_unixtime(time) > date_sub(curdate(), interval 7 day) ORDER BY `time` DESC LIMIT 10");
while ($row = dbGetRow($result)) {
$text = stripslashes($row['text']);
$time = $row['time'];
$author = stripslashes($row['author']);
echo " <li><span class=\"twitter_time\">".date('M j, Y, g:i a',$time)."</span> · $author: $text</li>\n" ;
}
echo "</ul>\n" ;
?>
但是,这只是将过去 7 天作为一个整体输出,而不是一次输出一个: http://sanctuary-westminster.org/server/scroll.php
问题是如何将最后一个条目(时间戳最大的条目)单独输出为“新闻项目”,所以最后一个帖子,倒数第二个帖子等。 它不会是固定数量的条目,一个 7 天可能是 10 个,另一个是 200 个,所以我发现编写 echo 和迭代很棘手。
提前谢谢你
【问题讨论】:
-
您是在寻找解决方案like on Facebook,在其中浏览新条目,还是需要pagination?
-
我会换种方式,用ajax获取推文,然后用js一一展示
-
我以前没有使用过 AJAX(或者真的有任何交易);我的代码试图适应我写到别人滚动代码中的 PHP 代码,所以谢谢你的建议,它让我知道如何以不同的方式做到这一点。