title: jquery chat with time
body: <p>I have one simple chat worked with jquery, PHP and MySQLi... All working perfect, but I need too add time of sender message like</p>
  
  <p><img src="https://i.stack.imgur.com/6sjzy.png" alt="enter image description here"></p>
  
  <p>or</p>
  
  <p><img src="https://i.stack.imgur.com/FnuJP.png" alt="enter image description here"></p>
  
  <p>ps. If I am on wrong place please tell me how and where I can write.</p>
  
  <p>Here is all code what I have in files, if someone want to use</p>
  
  <blockquote>
    <p>PHP file <strong>chat.php</strong>   like index.php</p>
  </blockquote>
  
  <pre><code>&lt;?php
  
  require('chat/core.inc.php');
  
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  
      &lt;link type="text/css" rel="stylesheet" href="public/css/main.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="input"&gt;
      &lt;div id="feedback"&gt;&lt;/div&gt;
      &lt;form action="#" method="post" id="form_input"&gt;
          &lt;labele&gt;Ime:&lt;br /&gt;&lt;input type="text" name="sender" id="sender" size="25"/&gt;&lt;/labele&gt;&lt;br /&gt;&lt;br /&gt;
          &lt;labele&gt;Poruka:&lt;br /&gt;&lt;textarea id="message" cols="61" rows="3"/&gt;&lt;/textarea&gt;&lt;/labele&gt;&lt;br /&gt;
          &lt;input type="submit" name="send" id="send" value="Posalji poruku"/&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;div id="messages"&gt;
  
  &lt;/div&gt;
  
  &lt;script type="text/javascript" src="script/js/jquery-1.11.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="script/js/auto_chat.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="script/js/send.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <blockquote>
    <p>In directory <strong>script/php</strong> I have files <strong>chat.php</strong> and <strong>send.php</strong></p>
  </blockquote>
  
  <p>chat.php</p>
  
  <pre><code>&lt;?php
  require('../../chat/baza/konekcija_db.php');
  require('../../chat/funkcija/chat.func.php');
  
  $messages = get_msg();
      foreach($messages as $message)
      {
          echo '&lt;strong&gt;' .$message['sender'].' poslao:&lt;/strong&gt;&lt;br /&gt;';
          echo $message['message'].'&lt;hr&gt;';
      }?&gt;
  </code></pre>
  
  <p>send.php</p>
  
  <pre><code>&lt;?php
  require('../../chat/baza/konekcija_db.php');
  require('../../chat/funkcija/chat.func.php');
  
  if(isset($_GET['sender'])&amp;&amp;!empty($_GET['sender'])) {
      $sender = $_GET['sender'];
  
      if (isset($_GET['message'])&amp;&amp;!empty($_GET['message'])){
          $message = $_GET['message'];
  
          if(send_msg($sender, $message)){
              echo 'Poruka je poslata';
  
          } else{
              echo 'Poruka nije poslata';
          }
  
      } else{
          echo 'Poruka nije unijeta';
      }
  
  } else{
      echo 'Ime nije unijeto';
  }?&gt;
  </code></pre>
  
  <blockquote>
    <p>In JS I have next:</p>
  </blockquote>
  
  <p>auto_chat.js</p>
  
  <pre><code>$(document).ready(function(){
  var interval = setInterval(function(){
      $.ajax({
          url: 'script/php/chat.php',
          success: function(data){
              $('#messages').html(data);
          }
      });
  }, 1000);
  </code></pre>
  
  <p>});</p>
  
  <p>send.js</p>
  
  <pre><code>$('#form_input').submit(function(){
  var message = $('#message').val();
  var sender  = $('#sender').val();
  
  $.ajax({
      url: 'script/php/send.php',
      data: { sender: sender, message: message},
      success: function(data){
          $('#feedback').html(data);
  
              $('#feedback').fadeIn('slow', function() {
                  $('#feedback').fadeOut(6000);
              });
          $('#message').val('');
      }
  });
  
  return false;
  </code></pre>
  
  <p>});</p>
  
  <blockquote>
    <p>and downloaded jquery-1.11.3.min</p>
  </blockquote>
  
  <p>now lets go in folder Chat where I have connection on database</p>
  
  <p>konekcija_db.php
      
  
  <pre><code>$db_host = 'localhost';
  $db_user =  'root';
  $db_pass =  '';
  
  $db_name =  'chat';
  
  if($connection = mysql_connect($db_host, $db_user, $db_pass))
  {
      $feedback[] = 'Konekcija na Bazu...&lt;br /&gt;';
  
      if($database = mysql_select_db($db_name, $connection))
      {
          $feedback[] = 'Baza je selektovana... &lt;br /&gt;';
      }else
      {
          $feedback[] = 'Baza nije pronadjena!&lt;br /&gt;';
      }
  }
  else{
      $feedback[] = 'Nije moguca konekcija na MYSQL server!&lt;br /&gt;';
  }?&gt;
  </code></pre>
  
  <blockquote>
    <p>chat function</p>
  </blockquote>
  
  <p>chat.func.php</p>
  
  <pre><code>&lt;?php
  
  function get_msg(){
  
      $query = "SELECT `Sender`, `Message` FROM `chat`.`chat` ORDER BY `Msg_ID` DESC";
  
      $run = mysql_query($query);
  
      $messages = array();
  
      while($message = mysql_fetch_assoc($run)){
          $messages[] = array('sender'=&gt;$message['Sender'],
                              'message'=&gt;$message['Message']);
      }
      return $messages;
  }
  function send_msg($sender, $message){
  
      if(!empty($sender) &amp;&amp; !empty($message)){
  
          $sender     =   mysql_real_escape_string($sender);
          $message    =   mysql_real_escape_string($message);
  
          $query = "INSERT INTO `chat`.`chat` VALUES (null, '{$sender}', '{$message}')";
  
          if($run = mysql_query($query)){
              return true;
          } else{
              return false;
          }
      }else{
          return false;
      }
  }?&gt;
  </code></pre>
  
  <p>and last file
  core.inc.php</p>
  
  <pre><code>&lt;?php
  $feedback = array();
  require('chat/baza/konekcija_db.php');
  require('chat/funkcija/chat.func.php');
  ?&gt;
  </code></pre>