title: Poll Database for Changes - Ajax/jQuery
body: <p>I have a issue. I'm creating an auction website like BidRivals or so.</p>
  
  <p>I'm currently working in the autcion script itself and its fully working but i have to ALWAYS reload the page every 5 seconds to check if there were new bids and that is not a good method in my point of view.</p>
  
  <p>So i'm optimizing the code so that the page ONLY refreshes if there were new bids.</p>
  
  <p>Currently i have this code:</p>
  
  <p>poll.php</p>
  
  <pre><code>include('../configs/db_ligar.php');          // db connection stuff..
  
  $query = "SELECT auction_id, auction_bid_counter FROM leilao WHERE auction_product_id = $id_prod";
  $result = mysql_query($query);
  
  if(mysql_num_rows($result) == 0) {
      echo -1;
  } else {
      $resultArray = array();
      $row = mysql_fetch_array($result);
      $resultArray['auction_id'] = $row['auction_id'];
      $resultArray['auction_bid_counter'] = $row['auction_bid_counter'];
      //Fast fix ... not pretty :)
  
    echo "[" . json_encode($resultArray) . "]"; 
  }
  </code></pre>
  
  <hr />
  
  <p>index.php</p>
  
  <pre><code>$(document).ready(function()
  {
      var checkTable = setInterval(function(){
          $.post('poll.php', function(resultData){
              //If there is data
              if(!resultData == -1){
                    //DIFFERENT: need to get the first element from the eval array
  
                  var resultObject = eval(resultData)[0];
  
                  alert('auction_id: ' + resultObject.auction_id + ' - auction_bid_counter: ' + resultObject.leilao_bid_counter);
  
              }
          }, 1000);    
      });
  });
  </code></pre>
  
  <hr />
  
  <p>Is this code incorrent?</p>