重新加载内的页面;与 $_GET
以下页面加载到我的index.php 中。我最初使用以下链接调用它:Import Mutuals
这部分工作得很好。我遇到的问题是底部的刷新代码: var auto_refresh = setInterval(function(){\$('#import').show('fast').load('fb_import_statuses.php?i=$ i').show('快');}, 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'>";
}
The following page loads inside of on my index.php. I initially call it using the following link: Import Mutuals
This part works dandy. The problem I'm having is with the refresh code at the bottom: var auto_refresh = setInterval(function(){\$('#import').show('fast').load('fb_import_statuses.php?i=$i').show('fast');}, 1000);
I want it to initially load with record 1 and then keep refreshing, updating my SQL until it reaches record 255. If I do this same code outside of a DIV using Meta Refresh it steps through the sequence fine, but using this JavaScript refresh it will sequence like this:
1, 2, 3, 2, 3, 4, 2, 3, 4, 5 etc...
How can I get it to sequence as 1, 2, 3, 4, 5, 6, 7 etc...
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'>";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您添加了多个 setInterval 函数(每次加载页面时您都会回显另一个方法)。尝试将您的刷新方法放在
div
之外,或者让它调用一个包含负责从数据库检索信息的php
代码的函数。如果您不必每秒刷新页面,您可以使用一个
php
文件从数据库获取所有数据,并以某种形式返回(例如json
) 。我认为这将是做到这一点的最好方法。the problem is that you add multiple
setInterval
functions (everytime the page is loaded youecho
another method). try putting your refreshing method out of thediv
or make it call a function that includesphp
code responsible for retrieving information from db.if you don't have to refresh the page every second, you could get all the data from db with one
php
file and return it in some form (json
for example). I think this would be the best way to do this.