How to improve the way that comments are shown in a chat box JavaScript/PHP
<p>I’ve made a chat box but, I have a problem when I delete an unwanted comment. I have a delete function associate to an onclick event for each comment inserted
This is how I show the comments:
(Comments are stored in a data base )</p>

<pre><code>var refreshMsg = setInterval(function() {
    $.post("chatFunc.php", { action: "load", id_userMsg: '&lt;?php echo $id_user; ?&gt;' },
function(dVLoadUsers) {
$("#divMsg").append(dVLoadUsers);   // appending the new comments into a div        $("#divMsg").scrollTop($("#divMsg")[0].scrollHeight);   
        }); 
}, 399); // Loop time in milliseconds
</code></pre>

<p>This is the delete function(jquery):</p>

<pre><code>function DeleteMsg(id_msg){
$.post("chatFunc.php", { action: "del", id_msgChat: id_msg, id_userMsg: '&lt;?php echo $id_user; ?&gt;' },
    function(dVLoad) {
        $("#divMsg").html(dVLoad);
        $("#inputMsg").val("").focus();
    }); 
}
</code></pre>

<p>This is action: “del” in php:</p>

<pre><code>if($action == "del"){
$msgDeleted = "Comment Deleted";
$qBorraMsj = mysqli_query($classDB-&gt;con,"UPDATE chat SET message = '$msgDeleted ' WHERE id LIKE '$id_msgChat'"); // Updating message content to "Comment Deleted"
$qChat = mysqli_query($classDB-&gt;con,"SELECT id, message, userNameFROM chat ORDER BY id ASC LIMIT 60"); // Getting the last 60 messages inserted
while($row = mysqli_fetch_array($qChat) ){
    if($row['message'] == $msgDeleted ) // Showing deleted messages
        echo '&lt;span class="styleUsName"&gt;'.$row['userName'].'&lt;/span&gt;:&amp;nbsp;&lt;span class="styleMsgDel"&gt;'.$row['message'].'&lt;/span&gt;&lt;/br&gt;';
    else // Showing the rest of the messages
        echo '&lt;span class="styleUsName"&gt;'.$row['userName'].'&lt;/span&gt;:&amp;nbsp;&lt;span class="styleMsgDel"&gt;'.$row['message'].'&lt;/span&gt;&amp;nbsp;&lt;span class="styleDelMsg" onClick="deleteMsg('.$row['id'].')"&gt;delete&lt;/span&gt;&lt;/br&gt;';
 }
}
</code></pre>

<p>So, basically when a message is deleted the div is reloaded with the last 60 messages inserted. It works for the guy who is deleting messages but not for everyone, because only him is executing the code.</p>

<p>How can I refresh the panel with messages for everybody ? Thanks for your time.</p>
