Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Autoupdate wall using Ajax?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36781
    schart
    Participant

    So 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 :)

    #97264
    bungle
    Member

    you 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);
    #97269
    bungle
    Member

    posts.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.

    #97274
    bungle
    Member

    can 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

    #97281
    bungle
    Member

    The network pane in Firebug should show you the ajax calls being made

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.