title: AJAX only update when changes in the database - Codeigniter
body: <p>I am trying to only update the page when their are updates in the database but i am unsure how to do that. </p>
  
  <p>I was thinking of comparing ids stored into the database because each ID is unique so if i make some sort of expression that compares the current array stored or picked up by AJAX to the ids in the database. But i am unsure how to compare ids and check if their is a new update</p>
  
  <p>Any help would be appreciated</p>
  
  <p>Controller</p>
  
  <pre><code>public function insertJSON()
      {
          $this-&gt;load-&gt;model("values");
          $queryresults = $this-&gt;values-&gt;getDb();
  
          $id = array();
          $arr = array();
          $arr2 = array();
  
  
          foreach($queryresults as $row)
          {
              $id[] = $row-&gt;id;
              $arr[] =  $row-&gt;post;
              $arr2[] = $row-&gt;img;
          }
  
              $data = array();
              $data[] = $id
              $data[] = $arr;
              $data[] = $arr2;
  
              echo json_encode($data);
      }
  </code></pre>
  
  <p>View</p>
  
  <pre><code> &lt;script type='text/javascript' language='javascript'&gt;
        $('#getdata').click(function () {
          $.ajax({
            url: '&lt;?php echo base_url().'index.php/welcome/insertJSON';?&gt;',
            async: false,
            type: "POST",
            success: function(data) {
  
              // thought i could do something like
                     if(data.change in database) do bla bla
  
              var id = data[0];
              var arr = data[1];
              var arr2 = data[2]
  
            }
          })
        });
      &lt;/script&gt;
  </code></pre>