title: How to make ajax long polling with php - mysql
body: <p>I made the php code which it gets rows from Asks table that are not read :</p>
  
  <pre><code>$sqlanum = "SELECT id FROM asks WHERE answer='' AND profile='1' AND askdate&gt;now()";
  $queryanum = mysqli_query($db_conx, $sqlanum);
  $rowanum = mysqli_num_rows($queryanum);
  </code></pre>
  
  <p>I am not familiar with Ajax long-polling , I just read about it few things and after searching for simple Ajax long-polling examples i made something like this :</p>
  
  <pre><code>$.ajax({
          type: "GET",
          url: "chkasks.php",
  
          async: true, /* If set to non-async, browser shows page as "Loading.."*/
          cache: false,
          timeout: 50000, /* Timeout in ms */
  
          success: function(data){ /* called when request completes */
              //addmsg("new", data);
              setTimeout(chkAsks, 1000);
          },
          error: function(XMLHttpRequest, textStatus, errorThrown){
              setTimeout(chkAsks, 3000);
          }
      });
  };
  </code></pre>
  
  <p>but I don't know how I can make it in a loop and break if there is results and continue looping i there is no results...</p>