title: how to make more efficient js for loop inside php while loop JSON
body: <p>I'm selecting values from my db in mysql and comparing them with values from JSON. I'm receiving the right results but since I'm using append the results shows up one by one, which looks like animation I would like to get them all at once and show some kind of loading icon while the loop is running, I've tried few different ways but nothing worked.</p>
  
  <pre><code>&lt;?php $sql= "select a_id,b_id,res_a,res_b from betts_gr where u_id='".$u_id[0]."'";
  $user_bets = mysqli_query($conn,$sql);
  
  while($user_bets1 = mysqli_fetch_array($user_bets)){
  ?&gt;
  &lt;script&gt;
      $(document).ready(function() {
          var a_id = "&lt;?php echo $user_bets1[0]?&gt;";
          .....
          var car = [];
          $.getJSON('http://api.football-api.com/2.0/matches? 
              comp_id = 1204 &amp; from_date = '+today+' &amp; to_date = '+plusmonth+' &amp; Authorization ', 
              function(data) {
                  var html = "";
                  console.log(data);
                  $.each(data, function(index, value) {
                      var teama = value.localteam_name;
                      var teamb = value.visitorteam_name;
                      .......
  
                      function add(name, point) {
                          car.push({
                              teamb: teamb,
                              teama: teama,
                              form: form,
                              data: data,
                              teama_id: teama_id,
                              teamb_id: teamb_id,
                              a_res: a_res,
                              b_res: b_res
                          });
                      }
  
                      add(teama, teamb, data, form, teama_id, teamb_id, a_res, b_res);
                  });
  
                  for (var n = 0; n &lt; car.length; n++) {
                      if (car[n].teama_id == a_id &amp;&amp; car[n].teamb_id == b_id) {
  
                          html += "&lt;tr&gt;&lt;td&gt;&lt;input type='hidden' name='aid" + n + "' 
                          value = '"+car[n].teama_id+"' &gt; &lt; input type = 'hidden'
                          name = 'bid"+n+"'                           
                          value = '"+car[n].teamb_id+"' &gt; " +
                              car[n].data +
                              "&lt;/td&gt;&lt;td&gt; " + car[n].teama + "&lt;/td&gt;&lt;td&gt;" + car[n].a_res + "-" +
                              car[n].b_res + "&lt;/td&gt;&lt;td&gt; " +
                              car[n].teamb + '&lt;/td&gt;&lt;td&gt; you predicted -&gt;' + pred_resa + ' - ' + pred_resb +
                              '&lt;/tr&gt;';
                      }
                  }
  
                  $(".message").append(html);
              });
      });
  &lt;/script&gt;
  &lt;?php  }  ?&gt;
  </code></pre>