嗨,我使用jQuery從另一個頁面加載信息每5秒鐘通過使用此代碼:如何只新職位的jQuery滑動
<script>
jQuery(function($){
$('#loaddiv').show();
})
var auto_refresh = setInterval(
function(){
$('#loaddiv').hide().load('reload.php').show();
}, 5000);
</script>
而這裏的reload.php:
<?php
session_start();
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$mysql=mysql_connect('localhost','***','***');
mysql_select_db('jmtdy');
$result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
$dbarray=mysql_fetch_assoc($result);
$id=$dbarray['id'];
$result1=mysql_query("select * from friendship where userid='".$id."'") or die(mysql_error());
$dbarray1=mysql_fetch_assoc($result1);
$userid=$dbarray1['friendid'];
$result2=mysql_query("select * from posts where userid='".$userid."' or userid='".$id."' ORDER BY id DESC LIMIT 20") or die(mysql_error());
if(mysql_num_rows($result2) >=1) {
while($dbarray2=mysql_fetch_assoc($result2)) {
echo '<div class="homestatus"><a class="homeusername" href="account.php?user='.$dbarray2['username'].'">'
.$dbarray2['fname'].' '.$dbarray2['lname'].':<a><p class="homepost">'
.$dbarray2['post'].'</p><p class="hometime">'.$dbarray2['time'].'</p></div>';
}
}
else {
echo '<p class="homestatus">No new updates from your friends.</p>';
}
?>
它的工作完美,但我的問題是,我怎麼能在新的結果排序的Quora如何在幻燈片中使用jQuery的問題新的答案滑動?
好吧,我想出了這一點:
<script>
jQuery(function($){
$('#loaddiv').show();
})
var auto_refresh = setInterval(
function(){
var timestamp = new Date().getTime() - 5000;
// get posts for the last 5 seconds only
var new_posts = $.load('reload.php?time=' + timestamp);
$('#loaddiv').append(new_posts).show('slow');
}, 5000);
</script>
這:
<?php
session_start();
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$mysql=mysql_connect('localhost','***','***');
mysql_select_db('jmtdy');
$result=mysql_query("select * from users where username='".$_SESSION['username']."'") or die(mysql_error());
$dbarray=mysql_fetch_assoc($result);
$id=$dbarray['id'];
$result1=mysql_query("select * from friendship where userid='".$id."'") or die(mysql_error());
$dbarray1=mysql_fetch_assoc($result1);
$userid=$dbarray1['friendid'];
$time=mysql_real_escape_string($_GET['time']);
$result2=mysql_query("select * from posts where userid='".$userid."' or userid='".$id."' and time='".$time."' ORDER BY id DESC LIMIT 20") or die(mysql_error());
if(mysql_num_rows($result2) >=1) {
while($dbarray2=mysql_fetch_assoc($result2)) {
echo '<div class="homestatus"><a class="homeusername" href="account.php?user='.$dbarray2['username'].'">'.$dbarray2['fname'].' '.$dbarray2['lname'].':<a><p class="homepost">'.$dbarray2['post'].'</p><p class="hometime">'.$dbarray2['time'].'</p></div>';
}
}
else {
echo '<p class="homestatus">No new updates from your friends.</p>';
}
?>
但我得到這個錯誤: 公告:未定義的索引:在/ var/WWW時間/ Cliproid/reload.php上線13
但如果我真的動畫所有職位滑入。怎麼我只能動畫新職位? – 2011-02-15 15:18:00