title: A real-time notification system (created using jquery/Ajax) doesn't work correctly
body: <p>I am trying to build a real-time notification system using jquery/Ajax for the social network web site I am developing (using Symfony2). I succeeded to make that notification system work but the issue is that it doesn't work correctly. The explanation is below:</p>
  
  <p>I downloaded wdCalendar calendar (from this link: <a href="http://www.webappers.com/2010/06/08/wdcalendar-jquery-based-google-calendar-clone/" rel="nofollow">http://www.webappers.com/2010/06/08/wdcalendar-jquery-based-google-calendar-clone/</a> and you can have a look at this link to see the demo: <a href="http://www.web-delicious.com/jquery-plugins-demo/wdCalendar/sample.php" rel="nofollow">http://www.web-delicious.com/jquery-plugins-demo/wdCalendar/sample.php</a>) and I integrated it on Symfony2. Then I created three files: mapage.html , moslem.php and moslem1.php . The code of each file is shown below:</p>
  
  <p>the code of mapage.html:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
  $(document).ready(function() {
          setTimeout( test, 1000);    
  });
      function test() {
          var start = new Date().getMilliseconds();
          $.ajax({
              url: 'moslem.php',
              type: 'POST',
              success: function(data) {
                  var max;
                  max = data;
                  function test1() {
                      $.ajax({
                          url: 'moslem1.php',
                          type: 'POST',
                          dataType: 'JSON',
                          success: function(data1) {
                              if(data1.id&gt;max)
                              {
                                  document.write("an event was added with the id: "+data1.id+" and with the subject: "+data1.subject+"&lt;br&gt;");
                              }
                          }
                      });
                  }
                  var end = new Date().getMilliseconds();
                  var time = end - start;
                  var time1 = 1000 - time;
                  setTimeout( test1, time1);
      }
          });
          setTimeout( test, 1000);    
  }
      &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>the code of moslem.php :</p>
  
  <pre><code>    &lt;?php
  $con=mysqli_connect("localhost","root","","test");
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
  $num_rows = mysqli_num_rows($result);
  if($num_rows!=0){
  while($row = mysqli_fetch_array($result)) {
      $max=$row['Id'];
  }
  echo $max;
  }
  mysqli_close($con);
  ?&gt;
  </code></pre>
  
  <p>the code of moslem1.php :</p>
  
  <pre><code>    &lt;?php
  $con=mysqli_connect("localhost","root","","test");
  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  $result = mysqli_query($con,"SELECT * FROM jqcalendar ORDER BY id DESC LIMIT 0, 1");
  while($row = mysqli_fetch_array($result)) {
      $notification = array('id'=&gt;$row['Id'],'subject'=&gt;$row['Subject'],'location'=&gt;$row['Location'],'description'=&gt;$row['Description'],'starttime'=&gt;$row['StartTime'],'endtime'=&gt;$row['EndTime']);
  }
  echo json_encode($notification);
  mysqli_close($con);
  ?&gt;
  </code></pre>
  
  <p>In the database on which I am working there is a table called "jqcalendar", its structure is as below (the field name is on the left and the field type is on the right):</p>
  
  <p>Id               :               int(11)<br>
  Subject          :               varchar(1000)<br>
  Location         :               varchar(200)<br>
  Description      :               varchar(255)<br>
  StartTime        :               datetime<br>
  EndTime          :               datetime<br>
  IsAllDayEvent    :               smallint(6)<br>
  Color            :               varchar(200)<br>
  RecurringRule    :               varchar(500)                                               </p>
  
  <p>The field "Id" above is the primary key of the table "jqcalendar" and it is auto-incremented as well. Well, concerning the notion of the notification system that I am trying to build is as follows: when an event is added on the calendar, the insertion of the new line in the table "jqcalendar" will be detected thanks to a jquery/Ajax request (on the table "jqcalendar") which happens every one second, then the content of some fields (which are "Id" and "Subject") will be displayed on the screen (the file mapage.html is the one which display them) as a notification. The issue is that when I add the event with the id "10" the notification will be not displayed. By the way, I added 20 events in the calendar and this is the output of the notifications that I obtained on the screen:</p>
  
  <p>an event was added with the id: 1 and with the subject: a<br>
  an event was added with the id: 2 and with the subject: z<br>
  an event was added with the id: 3 and with the subject: e<br>
  an event was added with the id: 4 and with the subject: r<br>
  an event was added with the id: 5 and with the subject: t<br>
  an event was added with the id: 6 and with the subject: y<br>
  an event was added with the id: 7 and with the subject: u<br>
  an event was added with the id: 8 and with the subject: i<br>
  an event was added with the id: 9 and with the subject: o<br>
  an event was added with the id: 11 and with the subject: ^^<br>
  an event was added with the id: 12 and with the subject: q<br>
  an event was added with the id: 13 and with the subject: s<br>
  an event was added with the id: 14 and with the subject: d<br>
  an event was added with the id: 15 and with the subject: f<br>
  an event was added with the id: 16 and with the subject: g<br>
  an event was added with the id: 17 and with the subject: h<br>
  an event was added with the id: 18 and with the subject: j<br>
  an event was added with the id: 19 and with the subject: k<br>
  an event was added with the id: 20 and with the subject: l                                  </p>
  
  <p>As you can notice it clearly above, there is a missed notification which is the one of the event with the id "10". Just focus on the two lines below:</p>
  
  <p>an event was added with the id: 9 and with the subject: o<br>
  an event was added with the id: 11 and with the subject: ^^                                </p>
  
  <p>So my question is how shall I make the notification of the event with id=10 appears like the other notifications. I really wonder what is the problem here and why exactly the notification of the event which has id=10 can't be displayed!. I have tried to find a solution for a long time but nothing has changed. Is there anyone who any idea??</p>
  
  <p>Thanks in advance.</p>