title: Javascript can't read my json array
body: <p>So I took some data from my database and placed it in a json array using the following code: </p>
  
  <p>getDataFromDB:</p>
  
  <pre><code>&lt;?php
  
  include"connectToDB.php";
  //voert de volgende query uit
  $result = $db-&gt;query("SELECT * FROM youtubevideos");
  
  $array = array();
  
  while($row = $result-&gt;fetch_assoc()) {
      $array = $row;
      echo json_encode($array);
  }
  ?&gt;
  </code></pre>
  
  <p>dataToHTML.js:</p>
  
  <pre><code>$.getJSON("getDataFromDB.php", function(result){
      $.each(result, function(i, field){
          console.log(field);
      });
  });
  </code></pre>
  
  <p>In the console.log(field) it's supposed to give me all the data from the array. But for some reason my console is empty. It seems like it can't read my array. But the funny thing is... 
  When I type <code>exit();</code> after this line of code <code>echo json_encode($array);</code> in my php file it somehow can read it. But the problem is is that it only gives me a single row from my database. Ofcourse I want to get all the data from my database, so I can't use <code>exit();</code>. Are their any other suggestions about what I'm doing wrong?
  Thanks!</p>