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_ar开发者_开发百科ray($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 problem is that you add multiple setInterval
functions (everytime the page is loaded you echo
another method). try putting your refreshing method out of the div
or make it call a function that includes php
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.
精彩评论