I have created a relatively simple "ideas board" in PHP/jQuery/MySQL.
On page load the div #chat pulls the current entries in the database.
<div id="chat"> <?php $sql = "SELECT * from idea ORDER BY id DESC;"; $result = $pdo->query($sql); if($result->rowCount() > 0 && !empty($result)) { foreach ($result as $row) { $title = $row['title']; $idea = $row['idea']; echo '<span class="idea"><strong>' . $row['title'] . "</strong> - " . $row['idea'] . ' <a class="delete" href="">[Delete]</a></span>'; } } ?> </div> However I'd like it to be refreshed periodically using:
<body onload="setInterval('chat.update()', 1000)"> The below example details how it can be done using a text file, how would I do it with querying a database (the example was found at http://css-tricks.com/jquery-php-chat/)?
//Updates the chat function updateChat() { if(!instanse){ instanse = true; $.ajax({ type: "POST", url: "process.php", data: {'function': 'update','state': state,'file': file}, dataType: "json", success: function(data) { if(data.text){ for (var i = 0; i < data.text.length; i++) { $('#chat-area').append($(" "+ data.text[i] +" ")); } } document.getElementById('chat-area').scrollTop = document.getElementById('chat-area').scrollHeight; instanse = false; state = data.state; } }); } else { setTimeout(updateChat, 1500); } } I expect certain rows to be deleted as well, so on top of entries being appended, I'd also like some to be removed.
It should simulate a real-time conversation.