- This topic is empty.
-
AuthorPosts
-
February 22, 2012 at 7:13 am #36781
schart
ParticipantSo I’m using a
while
statement to line every wall post in a table. Now I want to refresh this every 10 seconds using ajax, possibly setInterval.
Here is my wall script:
$limit = $_GET;
if (empty($limit)){
$limit = "20";
}
$wallquery = mysql_query("SELECT * FROM users_wall
WHERE id = '$pageidz' ORDER BY unique_id DESC LIMIT 0, $limit");
while ($row = mysql_fetch_assoc($wallquery)){
$wname = $row;
$comment = $row;
$widz = $row;
$uniz = $row;
$isreply = $row;
$commentlimit = substr($comment, 0, 100). "...Full Post";
$wid = $row;
$wimg2 = $row;
$timestamp1 = $row;
$timestamp2 = substr($timestamp1, 5, -3);
$timestamp3 = str_replace("-", ".", $timestamp2);
$timestampf = substr($timestamp1, 0, 10);
$timestampc = substr($timestamp3, 6, 11);
$timestamp4 = "" .$timestampc. " " .$timestampf. "";
$timestamp = str_replace("-", ".", $timestamp4);
$wallimg = mysql_query("SELECT * FROM users
WHERE id = '$wid'");
while ($row = mysql_fetch_assoc($wallimg)){
$wimg = $row;
}
?>
">
">
// Ignore all of this, CSS-Tricks! Just some user validation things like delete and reply
if($username == $wname || $username == $uname){ ?> |
| 0){ ?> | " style="color:#aaa;font-size:12px;">Replies () |
100){ echo($commentlimit); }else{ echo($comment); } ?>
}
?>
Any ideas? :)
– Thanks :)
February 22, 2012 at 9:41 pm #97264bungle
Memberyou need to give the table an id so you can refer to it and then put that inside another div that will function as the container
and then use the jquery load() function to load the page via ajax and insert just the table into the div
function refreshPosts(){
$('#container').load('posts.php #table');
}
setInterval('refreshPosts()',10000);
February 22, 2012 at 10:16 pm #97269bungle
Memberposts.php could just be the original page – your index.php if that is what it is called, it can reload itself effectively as it only pulls out the bits it needs
I would normally however create a stripped down version for ajax purposes so that it loads faster. A thought would be to then include that posts.php from your original file so you only have one copy of the code to maintain.
February 22, 2012 at 10:40 pm #97274bungle
Membercan you use firebug to see if the ajax is requesting the page?
To fault find I would add a button to trigger the refreshPosts function manually, make sure that there isn’t an issue with that first
February 22, 2012 at 11:57 pm #97281bungle
MemberThe network pane in Firebug should show you the ajax calls being made
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.