jquery refresh php loop?

Posted by Elliott on Stack Overflow See other posts from Stack Overflow or by Elliott
Published on 2010-04-22T13:41:27Z Indexed on 2010/04/22 13:43 UTC
Read the original article Hit count: 283

Filed under:

Hi, I have a page in which users can make "posts" its similar to facebook, I am trying to figure out how I can get it to run the php loop say every 10mins, in order for the person to see new posts. Everytime a post is made it is added into the db and then the page is refreshed, I want to do it more "facebook like". Using jquery slide down etc. Below is what I have up2 now.

function postdata()
{
    $.ajax({
    type: "POST",
    dataType: "text",
    url: "makepost.php",
    data: "post_text=" + $("#post_text").val(),
    cache: false,
    success: function(reply_text)
    {
        if (reply_text.indexOf("Successful") >= 0)
        {
            alert("Post Made");
            window.location = "index.php"


        }
        else 
        {
            alert(reply_text);
        }
    }
    });
}

</script>

    <div id="content">
<?php

if (loggedin())
{

$ID = getID();
$query = "SELECT * FROM `posts`";
$result=mysql_query($query);
$count=mysql_num_rows($result);

$users = "SELECT `userID` FROM `users`";
$resultID=mysql_query($users);


while ($row = mysql_fetch_array($result)) 
{   

echo '<div class="posts">';

    echo $row['2']."<br /><br />";      

        echo '<div class="posts_bottom">';

            echo '<p class="name">';

            echo showuser($row['1'])."</p>";

            echo '<p class="rate">';

            echo '<input type="submit" value="+1"/></p>';   

            echo '<p class="points">';

            echo showpoints($row['1'])."</p>";

        echo "</div>";

echo '</div>';

}
echo 
'<div id="makepost">
    <br /><textarea rows="3" cols="25" id="post_text" ></textarea><br />
    <input type="submit"  id="post_bttn" value="Post" onclick="postdata(); return false;">  
</div>';

As they are put into a new div everytime I don't know what to refresh? Such as if it was one div I could jus refresh that, but these are being created and I don't know how many would need to be loaded.

Any adivce? Thanks alot :D

© Stack Overflow or respective owner

Related posts about jQuery