使用$ _GET </div>重新加载<div>中的页面

时间:2011-09-22 04:19:50

标签: javascript ajax html refresh

以下页面加载到我的index.php中。我最初使用以下链接调用它:导入Mutuals

这部分花花公子。我遇到的问题是底部的刷新代码:var auto_refresh = setInterval(function(){\ $(&#39; #import&#39;)。show(&#39; fast&#39; ).load(&#39; fb_import_statuses.php?i = $ i&#39;)。show(&#39; fast&#39;);},1000);

我希望它最初加载记录1,然后保持刷新,更新我的SQL,直到它达到记录255.如果我使用Meta Refresh在DIV之外执行相同的代码,它会顺序完成序列,但使用此JavaScript刷新它会像这样排序:

1,2,3,2,3,4,2,3,4,5等...

如何让它按顺序排列为1,2,3,4,5,6,7等......

require 'batch_include.php';
require 'html_head.php';

if (isset($_GET['i'])){$i = $_GET["i"];} else {$i=0;}

$getcount = mysql_query("SELECT COUNT(id) AS get_count FROM people", $conn);
while ($row = mysql_fetch_array($getcount)){$get_count = "".$row{'get_count'}."";}

   $result = mysql_query("SELECT id FROM people LIMIT ".$i.",1", $conn);
   while ($row = mysql_fetch_array($result)){                                    
        $get_uid = addslashes("".$row{'id'}.""); 

    $me_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT     status_id, message, source, time FROM status WHERE uid="'.$get_uid.'" LIMIT 5'));
    foreach ($me_friends as $fkey=>$me_friends){
        $get_status_id = $me_friends['status_id']; 
        $get_message = addslashes($me_friends['message']); 
        $get_source = $me_friends['source']; 
        $get_timestamp = $me_friends['time']; 

    $insert = mysql_query("INSERT INTO statuses (id, message, source, timestamp, uid)      VALUES ('$get_status_id', '$get_message', '$get_source', '$get_timestamp', '$get_uid')",     $conn);        
    }  
}             
$i = $i + 1;

if ($i<=$get_count){
echo "$i";
echo "<script>var auto_refresh = setInterval(function(){\$('#import').show('fast').load('fb_import_statuses.php?i=$i').show('fast');}, 1000);    </script>";
}

else {    
    echo "Import complete:  ";
    echo "<img src='/images/check.png'>";

    } 

1 个答案:

答案 0 :(得分:0)

问题是您添加了多个setInterval函数(每次页面加载时echo另一种方法)。尝试将刷新方法从div中删除,或者让它调用包含负责从db检索信息的php代码的函数。

如果您不必每秒刷新页面,您可以使用一个php文件从db获取所有数据,并以某种形式返回它(例如json)。我认为这是最好的方法。

相关问题