title: script execute again if the database have changes
body: <p>can anyone help me how to do that my script only automatically execute again if the database has some changes only....in my current script it executes all the time according to the var <code>timer</code> <code>setInterval</code> in order to automatically update the output of the <code>textboxes</code> if i change the value in the database without the page refreshing or click the button again to execute the script.</p>
  
  <p>i want to do is it will only execute again if there is some value changes in the table in the database...anyone know how to do it?</p>
  
  <p>script code:</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
  var timer ;
  $('#send_search_form').click(function(event){
          event.preventDefault();
          $(".search_form_input").val('');
          $(".empty_batchcode").html("Doesn't exist!");
          clearInterval(timer);
          updateTextboxes();
  
  });
  var $funiq_id         = $('#funiq_id'),
      $t_region         = $('#t_region'),
      $t_town           = $('#t_town'),
      $t_uniq_id        = $('#t_uniq_id'),
      $t_position       = $('#t_position'),
      $t_salary_grade   = $('#t_salary_grade'),
      $t_salary         = $('#t_salary');
  
  function updateTextboxes(){
          $.ajax({
          url:"search.php",
          type:"GET",
          data: { term : $('#query').val() },
          dataType:"JSON",
          success: function(result) {
  
          var ii = 1;
  
          for (var i = 0; i &lt; result.length; i++) { 
                      $funiq_id.html(result[i].value).show(); // reference
                      $t_region.val(result[i].region).show(); // reference
                      $t_town.val(result[i].town).show(); // reference
                      $t_uniq_id.val(result[i].uniq_id).show(); // reference
                      $t_position.val(result[i].position).show(); // reference
                      $t_salary_grade.val(result[i].salary_grade).show(); // reference
                      $t_salary.val(result[i].salary).show(); // reference
                      $('#id'+ii+'').val(result[i].atid).show();
                      $('#aic'+ii+'').val(result[i].atic).show();
                      $('#name'+ii+'').val(result[i].atname).show();
                      $('#other_qual'+ii+'').val(result[i].other_sum).show();
                      $('#interview'+ii+'').val(result[i].interview_sum).show();
              ii++;
              }
  
  
          if(timer == 1){
  
              timer = setTimeout(updateTextboxes,1000); 
          }
  
          }
  
  
      });
  
     timer = setInterval(updateTextboxes,50000);
  }
  });      
   &lt;/script&gt;
  </code></pre>
  
  <p>search.php code:</p>
  
  <pre><code>&lt;?php
  
  if (isset($_GET['term'])) {
  
      $q = $_GET['term'];
      mysql_connect("localhost", "root", "");
      mysql_select_db("klayton");
      $query = mysql_query
  ("
  SELECT DISTINCT 
  ROUND((SELECT SUM(t2.inttotal)
   FROM app_interview2 AS t2 
   WHERE t2.atic = t.atic)/7,1)
   AS interview_sum,
  
  ROUND((SELECT SUM(o2.ototal)
   FROM other_app2 AS o2 
   WHERE o2.oaic = t.atic)/7,1)
   AS other_sum,
  
  atid,
  atic,
  atname,
  region,
  town,
  uniq_id,
  position,
  salary_grade,
  salary
  FROM app_interview2 AS t
  WHERE uniq_id = '$q'
  GROUP BY t.atname HAVING COUNT(DISTINCT t.atic) ");
  
      $data = array();
  
      while ($row = mysql_fetch_array($query)) {
          $data[] = array(
              'value' =&gt; $row['uniq_id'],
              'atid' =&gt; $row['atid'],
              'atic' =&gt; $row['atic'],
              'region' =&gt; $row['region'],
              'town' =&gt; $row['town'],
              'uniq_id' =&gt; $row['uniq_id'],
              'position' =&gt; $row['position'],
              'salary_grade' =&gt; $row['salary_grade'],
              'salary' =&gt; $row['salary'],
              'atname' =&gt; $row['atname'],
              'other_sum' =&gt; $row['other_sum'],
              'interview_sum' =&gt; $row['interview_sum']
          );
      }
  
      header('Content-type: application/json');
      echo json_encode($data);
  
  }
  
  ?&gt;
  </code></pre>