Automatically updating chatbox
<p>So i'm working on a javascript/php chatbox. Everything works except for it updating the contents of my div (this works once, but after that it doesn't keep updating it when a new message has been put into the database). Here is my code:</p>

<p>Javascript part:</p>

<pre><code>   &lt;script language=javascript type='text/javascript'&gt; 

        setInterval(function () {

            var arrayOfObjects = &lt;?print_r(getChatArray());?&gt;;
            var chat = "";

            for (var i = 0; i &lt; arrayOfObjects.length; i++) {
                var object = arrayOfObjects[i];

                chat += "["+object.date+"]"+object.op+": " + object.msg + "&lt;/br&gt;";
            }
            $('#chat').html(chat);

        }, 10);
    &lt;/script&gt;
</code></pre>

<p>Php part:</p>

<pre><code>&lt;?php
function getChatArray() {
    $result = mysql_query("SELECT * FROM shouts ORDER BY id DESC"); 
    $to_encode = array();

    $count = mysql_num_rows($result);
    $size = 0;
        if($count &gt; 0) {
            while($row = mysql_fetch_assoc($result)) {
              $to_encode[$size]['id'] = $row['id'];
              $to_encode[$size]['msg'] = $row['msg'];
              $to_encode[$size]['op'] = $row['op'];
              $to_encode[$size]['date'] = $row['date'];
              $size += 1;
            } 

        } else {
            return "None";
        }

return json_encode($to_encode);
}
?&gt;
</code></pre>

<p>Any ideas as to why it isn't continually updating it?</p>

<p>Thanks.</p>
