title: How to stop user from sending request for the same time slot?
body: <p>I have this page in php where the user can click on the time slot and book a room. Now the issue I have found is Suppose an user1 books room from 4 to 6. Then another user2 comes &amp; request the room from 3.30 to 5. It takes the request which should not be allowed. The request is sent to admin and saved in the database i.e MySQL.</p>
  
  <p>The worry is if the admin rejects the request of user1 then user2 should be allowed. But if admin accepts user1 request then user2 should be given an error message or something to stop the booking of same time slot. Really confused how to stop this.</p>
  
  <pre><code>&lt;?php session_start(); if(isset($_GET[ 'selecteddate'])) { $selecteddate=$_GET[ 'selecteddate']; } else { $selecteddate=date( "Y-m-d"); } ?&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;title&gt;MRA&lt;/title&gt;
      &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css"&gt;
      &lt;style&gt;
          #heading {
              text-align: right;
              font-size: 25px;
              float: right;
              margin: 50px 20px;
          }
  
          a:hover {
              color: #BEBEBC;
          }
  
          a {
              color: black;
          }
  
          #img {
              margin: 10px 10px;
          }
  
          #td {
              border-radius: 15px;
              border-style: dotted solid;
          }
  
          .name-error,
          .meeting-error {
              color: red;
              margin: 0 10px;
          }
  
          #plan {
              position: fixed;
              left: 50%;
              margin-left: -239px;
              top: 50%;
              margin-top: -150px;
              z-index: 10;
              background-color: #fff;
              padding: 10px;
          }
  
          #plan-bg {
              width: 100%;
              height: 100%;
              position: fixed;
              background: #000;
              opacity: 0.8;
              top: 0;
              display: none;
              z-index: 5;
          }
  
          .close {
              position: absolute;
              top: 5px;
              right: 10px;
              cursor: pointer;
          }
  
          .close:hover {
              text-decoration: underline;
          }
  
          #datepicker {
              width: 40%;
              float: left;
          }
  
          .calender-date {
              padding: 0 10px;
          }
  
          #time-slot-msg,
          #alert-msg {
              position: fixed;
              top: 50%;
              left: 50%;
              background: #fff;
              font-size: 25px;
              padding: 10px 20px;
              margin: -50px 0 0 -184.5px;
              display: none;
              z-index: 10;
              border-radius: 5px;
          }
  
          #time-slot-msg p,
          #alert-msg p {
              font-weight: bold;
          }
  
          #time-slot-msg .close,
          #alert-msg .close {
              font-size: 15px;
              right: 20px;
          }
      &lt;/style&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          $(document).ready(function() {
              var $index;
              var systemdate = new Date();
              $('.meeting-error').hide();
              $(".meeting-timetable tr &gt; td + td").click(function(e) {
                  if ($(this).hasClass('active')) {
                      e.preventDefault();
                      alert('The selected time slot has already been assigned');
                  } else {
                      var $thisVal = $(this).prevAll('td:first-child').text();
                      var hour = $thisVal.substr(0, 2);
                      var min = $thisVal.substr(3, 3);
                      var d = new Date("&lt;?php print $selecteddate; ?&gt;");
                      var n = d.getFullYear();
                      var m = d.getDate();
                      var k = d.getMonth();
                      var userdate = new Date(n, k, m, hour, min, 0);
                      if (systemdate &gt; userdate) {
                          alert("Select Time Slot greater than the Current Time");
                          return;
                      }
                      $index = $(this).index();
                      // Start time.
                      $(".start-time option").each(function() {
                          if (($(this).text() === $thisVal)) {
                              $(this).attr('selected', 'selected');
                              $(this).prevAll().attr('disabled', 'disabled');
                          }
                      });
                      // Change end time.
                      $(".end-time option").each(function() {
                          if (($(this).text() === $thisVal)) {
                              $(this).next().attr('selected', 'selected');
                              $(this).attr('disabled', 'disabled');
                              $(this).prevAll().attr('disabled', 'disabled');
                          }
                      });
                      // Date input select.
                      var $date = $('.meeting-timetable tr:first-child th').text();
                      var dateFormat = $.datepicker.formatDate('yy-mm-dd', new Date($date));
                      $('.date').val(dateFormat);
                      $('#meeting').val('');
                      $('.meeting-error').hide();
                      // Show dialog box.
                      var _cellIndex = $(this)[0].cellIndex;
                      var _rowIndex = $(this).closest('tr')[0].sectionRowIndex;
                      var total_row = $('.meeting-timetable tr').length - 1;
                      if (_rowIndex == total_row &amp;&amp; _cellIndex == 1) {
                          alert('You cannot select this time slot');
                      } else $('#plan, #plan-bg').fadeIn();
                  }
              });
              // On submit click change background color.
              $('.submit-button').click(function(e) {
                  e.preventDefault();
                  var selectedValue = $(".start-time option:selected").text(),
                      selectedEndValue = $(".end-time option:selected").text(),
                      $name = $('input[name=txtname]').val();
                  if ($('#meeting').val()) {
                      $(".meeting-timetable tr &gt; td").each(function() {
                          if ($(this).text() === selectedValue) {
                              $(this).parent('tr').addClass('active');
                          }
                          if ($(this).text() === selectedEndValue) {
                              var $parent = $(this).parent('tr').prevUntil('tr.active').addClass('active');
                          }
                          // Prev all td selected.
                          $($parent).each(function() {});
                      });
                  }
                  // Form validation.
                  if ($('#meeting').val() === '') {
                      $('.meeting-error').fadeIn();
                  }
                  // Grab form values
                  var formData = {
                      'txtrname': $('input[name=txtrname]').val(),
                      'txtname': $('input[name=txtname]').val(),
                      'txtpurpose': $('input[name=txtpurpose]').val(),
                      'attendee': $('select[name=attendee]').val(),
                      'txtdate': $('input[name=txtdate]').val(),
                      'btime': $('select[name=btime]').val(),
                      'etime': $('select[name=etime]').val()
                  };
                  if ($('#meeting').val().trim()) {
                      // Ajax form submit.
                      $.ajax({
                          type: "POST",
                          url: "insertkarma.php",
                          data: formData,
                          success: function() {
                              $('#alert-msg').fadeIn();
                              $('#plan').fadeOut();
                          }
                      });
                  } else {
                      alert('Please enter the purpose of meeting');
                  }
              });
              // on focus function
              $('#meeting').focus(function() {
                  $('.meeting-error').fadeOut();
              }).blur(function() {
                  if (!$(this).val()) {
                      $('.meeting-error').fadeIn();
                  }
              });
              $(".close").click(function() {
                  $('.pop-up').fadeOut();
              });
              // Adding calender.
              $("#datepicker").datepicker({
                  minDate: 0,
                  dateFormat: "yy-mm-dd",
                  onSelect: function(date) {
                      var url = "karma.php?selecteddate=" + date;
                      window.location.assign(url);
                  }
              });
          });
      &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body background="a6.jpg"&gt;
      &lt;a href="homepage.php"&gt;&lt;img id="img" src="HITECHLOGO.jpg" width="150px" height="100px"&gt;&lt;/a&gt;
      &lt;h1 align="center" style="position:absolute;top:30px; left:600px;"&gt;KARMA&lt;br&gt; (3-SEATER)&lt;/h1&gt;
      &lt;div id="heading"&gt;&lt;a href="homepage.php" style="text-decoration:none;"&gt;Home&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;?php echo ucwords($_SESSION[ 'usr_name']); ?&gt;
          &lt;/font&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="logout.php" style="text-decoration:none;"&gt;Logout&lt;/a&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="UserManual.pdf" target="_blank" style="text-decoration:none;"&gt;Help&lt;/a&gt;
      &lt;/div&gt;
      &lt;hr width="100%"&gt;
      &lt;?php $host="localhost" ;  $username="root" ;  $password="" ; $db_name="testing" ;  $conn=mysqli_connect($host,$username,$password) or die( "cannot connect"); mysqli_select_db($conn,$db_name); $i=0 ; $dateEntry="SELECT `starttime` , `status_id` , `name` , floor(( time_to_sec(`endtime`)-time_to_sec(`starttime`) )/1800) as testing FROM `details` WHERE `date` = '$selecteddate' order by starttime" ; if ($result=mysqli_query($conn,$dateEntry)) { while ($obj=mysqli_fetch_object($result)) { $starttime[$i]=$ obj-&gt;starttime; $status[$i] = $obj-&gt;status_id; $name[$i] = $obj-&gt;name; $testing[$i] = $obj-&gt;testing; $i++; } } mysqli_close($conn); ?&gt;
      &lt;table border="1" align="right" width="60%" style="border:black;"&gt;
          &lt;tr&gt;
              &lt;td id="td" colspan="3" align="center"&gt;
                  &lt;h1&gt;Click to Book a Time Slot&lt;/h1&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td bgcolor="red" align="center" id="td"&gt;Booked&lt;/td&gt;
              &lt;td id="td" align="center" bgcolor="orange"&gt;Requested&lt;/td&gt;
              &lt;td align="center" id="td"&gt;Available&lt;/td&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="td" colspan="3"&gt;| &lt;a href="karma.php"&gt; Today &lt;/a&gt; |&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;table class="meeting-timetable" border="1" align="right" width="60%" style="border:black;"&gt;
          &lt;tr&gt;
              &lt;th id="td" colspan="2" class="calender-date" align="center"&gt;
                  &lt;?php print $selecteddate; ?&gt;
              &lt;/th&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="08:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; " width="10%"&gt;08:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="08:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;08:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="09:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;09:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="09:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;09:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="10:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;10:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="10:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;10:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="11:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;11:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="11:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;11:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="12:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;12:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="12:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;12:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="13:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;13:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="13:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;13:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="14:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;14:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="14:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;14:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="15:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;15:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="15:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;15:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="16:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;16:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="16:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;16:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="17:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;17:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="17:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;17:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="18:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;18:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="18:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;18:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="19:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;19:00&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="19:30:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;19:30&lt;/td&gt;
              &lt;td id="td"&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td id="20:00:00" align="center" style="border-radius: 15px;border-style: dotted solid; "&gt;20:00&lt;/td&gt;
              &lt;td id="td" class="showAlert"&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;div id="plan" class="pop-up" style="display :none "&gt;
          &lt;span class="close"&gt;Close&lt;/span&gt;
          &lt;form align="center" method="post" id="inform"&gt;
              &lt;h1 align="center"&gt;Meeting Details&lt;/h1&gt;
              &lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;b&gt;Room : &lt;/td&gt;&lt;td&gt;&lt;input type="text" name="txtrname" value="Karma" readonly&gt;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;b&gt;Name :&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="txtname" readonly value="&lt;?php echo ucwords($_SESSION['usr_name']);  ?&gt;"   &gt;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;b&gt;Purpose of Meeting :&lt;/td&gt;&lt;td&gt; &lt;input id="meeting" type="text" name="txtpurpose"&gt;&lt;span class="meeting-error"&gt;Enter the purpose of meeting&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;b&gt;No. of Attendee :&lt;/td&gt;&lt;td&gt;&lt;select name="attendee"&gt;&lt;option value="1"&gt;1&lt;/option&gt;&lt;option value="2"&gt;2&lt;/option&gt;&lt;option value="3"&gt;3&lt;/option&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;b&gt;Date :&lt;/td&gt;&lt;td&gt; &lt;input class="date" type="text" name="txtdate" readonly value="yyyy/mm/dd"&gt;&lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;b&gt;Time : &lt;/td&gt;&lt;td&gt;Start Time &lt;select class="start-time" name="btime"&gt;
       &lt;option value="08:00:00"&gt;08:00&lt;/option&gt;
       &lt;option value="08:30:00"&gt;08:30&lt;/option&gt;
       &lt;option value="09:00:00"&gt;09:00&lt;/option&gt;
       &lt;option value="09:30:00"&gt;09:30&lt;/option&gt;
       &lt;option value="10:00:00"&gt;10:00&lt;/option&gt;
       &lt;option value="10:30:00"&gt;10:30&lt;/option&gt;
       &lt;option value="11:00:00"&gt;11:00&lt;/option&gt;
       &lt;option value="11:30:00"&gt;11:30&lt;/option&gt;
       &lt;option value="12:00:00"&gt;12:00&lt;/option&gt;
       &lt;option value="12:30:00"&gt;12:30&lt;/option&gt;
       &lt;option value="13:00:00"&gt;13:00&lt;/option&gt;
       &lt;option value="13:30:00"&gt;13:30&lt;/option&gt;
       &lt;option value="14:00:00"&gt;14:00&lt;/option&gt;
       &lt;option value="14:30:00"&gt;14:30&lt;/option&gt;
       &lt;option value="15:00:00"&gt;15:00&lt;/option&gt;
       &lt;option value="15:30:00"&gt;15:30&lt;/option&gt;
       &lt;option value="16:00:00"&gt;16:00&lt;/option&gt;
       &lt;option value="16:30:00"&gt;16:30&lt;/option&gt;
       &lt;option value="17:00:00"&gt;17:00&lt;/option&gt;
       &lt;option value="17:30:00"&gt;17:30&lt;/option&gt;
       &lt;option value="18:00:00"&gt;18:00&lt;/option&gt;
       &lt;option value="18:30:00"&gt;18:30&lt;/option&gt;
       &lt;option value="19:00:00"&gt;19:00&lt;/option&gt;
       &lt;option value="19:30:00"&gt;19:30&lt;/option&gt;
       &lt;option value="20:00:00" disabled&gt;20:00&lt;/option&gt;
       &lt;/select&gt;
       - End Time &lt;select class="end-time" name="etime"&gt;
       &lt;option value="08:00:00"&gt;08:00&lt;/option&gt;
       &lt;option value="08:30:00"&gt;08:30&lt;/option&gt;
       &lt;option value="09:00:00"&gt;09:00&lt;/option&gt;      
       &lt;option value="09:30:00"&gt;09:30&lt;/option&gt;
       &lt;option value="10:00:00"&gt;10:00&lt;/option&gt;
       &lt;option value="10:30:00"&gt;10:30&lt;/option&gt;
       &lt;option value="11:00:00"&gt;11:00&lt;/option&gt;
       &lt;option value="11:30:00"&gt;11:30&lt;/option&gt;
       &lt;option value="12:00:00"&gt;12:00&lt;/option&gt;
       &lt;option value="12:30:00"&gt;12:30&lt;/option&gt;
       &lt;option value="13:00:00"&gt;13:00&lt;/option&gt;
       &lt;option value="13:30:00"&gt;13:30&lt;/option&gt;
       &lt;option value="14:00:00"&gt;14:00&lt;/option&gt;
       &lt;option value="14:30:00"&gt;14:30&lt;/option&gt;
       &lt;option value="15:00:00"&gt;15:00&lt;/option&gt;
       &lt;option value="15:30:00"&gt;15:30&lt;/option&gt;
       &lt;option value="16:00:00"&gt;16:00&lt;/option&gt;
       &lt;option value="16:30:00"&gt;16:30&lt;/option&gt;
       &lt;option value="17:00:00"&gt;17:00&lt;/option&gt;
       &lt;option value="17:30:00"&gt;17:30&lt;/option&gt;
       &lt;option value="18:00:00"&gt;18:00&lt;/option&gt;
       &lt;option value="18:30:00"&gt;18:30&lt;/option&gt;
       &lt;option value="19:00:00"&gt;19:00&lt;/option&gt;
       &lt;option value="19:30:00"&gt;19:30&lt;/option&gt;
       &lt;option value="20:00:00"&gt;20:00&lt;/option&gt;
       &lt;/select&gt;
       &lt;/td&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;/tr&gt;
       &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input class="submit-button" type="submit" value="Submit"    &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/form&gt;&lt;/div&gt;
       &lt;div id="plan-bg" class="pop-up"&gt;&lt;/div&gt;
       &lt;div id="alert-msg" class="pop-up"&gt;&lt;span class="close" onclick="window.location.reload();"&gt;Close&lt;/span&gt;&lt;p&gt;Your request has been sent to admin.&lt;/p&gt;&lt;/div&gt;
       &lt;div id="time-slot-msg" class="pop-up"&gt;&lt;span class="close"&gt;Close&lt;/span&gt;&lt;p&gt;This time slot is already booked.&lt;/p&gt;&lt;/div&gt;
       &lt;div id="datepicker"&gt;&lt;/div&gt;
       &lt;script type="text/javascript"&gt;
       var jqueryarray = [];
       jqueryarray = &lt;?php echo json_encode($starttime); ?&gt;;
       var statusarray=[];
       statusarray = &lt;?php echo json_encode($status); ?&gt;;
       var namearray=[];
       namearray = &lt;?php echo json_encode($name); ?&gt;;
       var countarray = [];
       countarray = &lt;?php echo json_encode($testing); ?&gt;;
       var arr = [];
       for(i = 0; i &lt; &lt;?php echo $i; ?&gt;; i++)
       {
          arr[i] = jqueryarray[i];
       }
       var brr = [];
       for(i = 0; i &lt; &lt;?php echo $i; ?&gt;; i++)
       {
         brr[i] = statusarray[i];
       }
       var crr=[];
       for(i=0; i&lt; &lt;?php echo $i; ?&gt;; i++)
       {
        crr[i] = namearray[i];
       } 
       var drr=[];
       for(i=0; i&lt; &lt;?php echo $i; ?&gt;; i++)
       {
        drr[i] = countarray[i];
       } 
       var j = 0;
       var k=1;
       var currentrow;
       $('.meeting-timetable tr').each(function() {
        if(arr[j] == $(this).find('td').attr('id')) 
        {
         if(brr[j]==1)
         {
           currentrow=$(this);
           for(k=1;k&lt;=parseInt(countarray[j]);k++)
           {
             currentrow.find('td').next().css('background-color','orange').addClass('active').attr("title",namearray[j]);
             currentrow=currentrow.next('tr');
           }
         }
         if(brr[j]==2)
         {
           currentrow=$(this);
           for(k=1;k&lt;=parseInt(countarray[j]);k++)
           {
             currentrow.find('td').next().css('background-color','red').addClass('active').attr("title",namearray[j]);
             currentrow=currentrow.next('tr');
           }
         }
         if(brr[j]==3)
         {
           $(this).find('td').next().css('background-color', '');
         }
         if(brr[j]==4)
         {
           $(this).find('td').next().css('background-color', '');
         }
         j++;  
         }
         });
         &lt;/script&gt;
         &lt;/body&gt;
         &lt;/html&gt;
  </code></pre>