title: Ajax returning a string and not array
body: <p>Previously I've successfully accessed a php array in a call back jquery ajax function by doing the following:</p>
  
  <pre><code>$.post('ajax.php', {name: name}, function(data) {
  
                  var obj = jQuery.parseJSON(data);
  
                  var item = obj[6]
  </code></pre>
  
  <p>With the php being:</p>
  
  <pre><code>$sql = "SELECT * FROM sales WHERE email = 'test' AND item = '$name' ";
  $result = mysqli_query($conn, $sql);
  
      if ($result){
                      $row = mysqli_fetch_array($result);
                      echo json_encode($row);
                      }
  </code></pre>
  
  <p>I have now the slightly different situation which i wouldn't have thought a problem but is, very much:</p>
  
  <p>PHP</p>
  
  <pre><code>$sql = "SELECT * FROM sales WHERE ".$searchwithin." BETWEEN '2017-02-01' AND     '2017-03-01'";
  
  $result = mysqli_query($conn, $sql);
      if ($result){   
                      while ($row = mysqli_fetch_assoc($result)){
  
                      echo json_encode($row);
                      }
  </code></pre>
  
  <p>When I do the following Jquery:</p>
  
  <pre><code> var obj = data.length;
  
   alert(obj);
  </code></pre>
  
  <p>I get a ridiculously high number which tells me that it's counted the string length and not the array length; so I guess that's the first problem, despite seemingly copying a successful past ajax, i am now getting a string returned and not an array.</p>
  
  <p>Finally, and I guess this relates to the first problem, whenever I use</p>
  
  <pre><code>var obj = jQuery.parseJSON(data);
  </code></pre>
  
  <p>it doesn't like it at all; i either get nothing, not even an alert, or i do get an alert with "undefined" returned.</p>
  
  <p>The array should contain eight or so mysqli table rows with fifteen columns; which i believe i then access with something like e.g. obj[5][7].  But I can't try that yet because it's returning a string, it seems, not an array.  I'm new to coding by the way and thanks in advance.</p>
  
  <p>Oh and this is what i get if i just do alert(data):</p>
  
  <p>{"id":"8", etc }</p>