title: setInterval for jQuery for loop trouble
body: <p>I am trying to run a specific for loop every x seconds, but cannot seem to make `setInterval work. I am sure my syntax is incorrect, yet, I cannot seem to get it right.</p>
  
  <p>I have added my full code below:</p>
  
  <p><strong>jQuery:</strong></p>
  
  <pre><code>//Click saves this.id as userID
  $(function() {
    var rTitle, rText, qTitle, qText, numRows, userID;
    $("#buttons").find(".btn").click(function() {
      $(this).parent().toggleClass('fullscreen');
      $(this).parent().siblings().toggleClass('master');
      var userID = this.id;
  
      //userID is then used for ajax to PHP script, information passed back is put in variables and generateProblems function is run
      $.ajax({
        type: "POST",
        url: 'include/responseget.php',
        dataType: 'json',
        data: {
          userID: userID
        },
        success: function(json) {
          rTitle = json.rTitle;
          rText = json.rText;
          qTitle = json.qTitle;
          qText = json.qText;
          next = json.next;
          numRows = json.numRows;
          id = json.id;
          generateProblems();
        }
      });
  
    });
    //Generate draggable html with an interval of 1000
    function generateProblems() {
      $('&lt;div&gt;' + qTitle + '&lt;/div&gt;').data('number', qTitle).attr('id', 'question').attr('class', 'bold').appendTo($("#" + id).parent()).hide().fadeIn(2000);
      for (var i = 0; i &lt; numRows; i++) {
        setInterval(function() {
          $('&lt;div&gt;' + rTitle[i] + '&lt;/div&gt;').data('number', next[i]).attr('id', +next[i]).appendTo($("#" + id).parent()).draggable({
            containment: '.site-wrapper',
            stack: '#testpile div',
            cursor: 'move',
            revert: true
          }).hide().fadeIn(2000)
          $('&lt;div&gt;' + rText[i] + '&lt;/div&gt;').data('number', next[i]).attr('id', +next[i]).appendTo($("#" + id).parent()).hide().fadeIn(2000);
        }, 1000);
      }
  
     //Rest of the code is not important, but I put it in nonetheless.
      $('#testdrop').droppable({
        drop: handleDropEvent,
        accept: '#testpile div'
      });
  
      function handleDropEvent(event, ui) {
        var problemNumber = ui.draggable.data('number');
        ui.draggable.draggable('disable');
        ui.draggable.draggable('option', 'revert', false);
        $("#testpile").children().hide();
  
        $.ajax({
          type: "POST",
          url: 'include/responseget.php',
          dataType: 'json',
          data: {
            userID: problemNumber
          },
          success: function(json) {
            rTitle = json.rTitle;
            rText = json.rText;
            qTitle = json.qTitle;
            qText = json.qText;
            next = json.next;
            numRows = json.numRows;
            generateProblems();
          }
        });
  
      }
    }
  });
  </code></pre>
  
  <p><strong>PHP:</strong></p>
  
  <pre><code>&lt;?php  include 'login.php';
      if(isset($_POST['userID'])){
          $id = $_POST['userID'];
          $stmt = $conn-&gt;prepare("SELECT DISTINCT AnswerTitle, AnswerText, QuestionTitle, QuestionText, Next FROM question_answers
          INNER JOIN question
          ON question_answers.QuestionID=question.QuestionID
          INNER JOIN answer
          ON question_answers.AnswerID=answer.AnswerID
          WHERE AnswerGroup = ?;");
          $stmt-&gt;bind_param('s', $id);
          $stmt-&gt;execute();
          $result = $stmt-&gt;get_result();
  
            while($row = $result-&gt;fetch_assoc()) 
            {
                $rTitle_array[] = $row['AnswerTitle'];
                $rText_array[] = $row['AnswerText'];
                $qTitle = $row['QuestionTitle'];
                $qText = $row['QuestionText'];
                $next_array[] = $row['Next'];
                $numRows = ($result-&gt;num_rows);
            }
  
          $response = array(
              'rTitle' =&gt; $rTitle_array,
              'rText'  =&gt; $rText_array,
              'qTitle' =&gt; $qTitle,
              'qText'  =&gt; $qText,
              'next'  =&gt; $next_array,
              'numRows'  =&gt; $numRows,
              'id'  =&gt; $id
          );
  
          echo json_encode($response);
      }
  
      // close connection
      mysqli_close($conn);
  ?&gt;
  </code></pre>