title: Why is my MySQL search query returning column names and data?
body: <p>I'm fairly new to PHP and I've been stumped on this issue for a while now (been searching everywhere but no help really).</p>
  
  <p>I'm attempting to search for all the data in a data table ("Select * FROM X") and that seems to work fine.</p>
  
  <p>However when I try to return/echo the data, encoding into JSON format as an array (I'd like 1 row as 1 index in the array) it does wierd things.</p>
  
  <p>Heres the code I currently use;</p>
  
  <pre><code>$SQL = "SELECT * FROM `units`";
  $Result = mysqli_query($link, $SQL) or die ("DB ERROR");
  $Total = mysqli_num_rows($Result);
  if($Total &gt; 0)
  {
      $rows = mysqli_fetch_array($Result, MYSQLI_NUM);
      $row_count = mysqli_num_rows($Result);
      while($row = mysqli_fetch_array($Result))
      {
          echo json_encode(array($row));
      }
  }
  </code></pre>
  
  <p>This then gets used in Unity (C#) via;</p>
  
  <pre><code>JSONObject obj = new JSONObject(loadUnitsWWW.text);
  Debug.Log(obj);
  </code></pre>
  
  <p>The results of which are;</p>
  
  <blockquote>
    <p>[{"0":"2", "unitID":"2","1":"Tanks","unitName":"Tanks","2":"Ground","unitType":"Ground"},[],[],[],[],[],[],[],[],[],[],[]]</p>
  </blockquote>
  
  <p>it seems to be trying to return EVERYTHING for some reason, including the column names. But I've no idea why it'd return the same results multiple times (and no idea where the 0 came from).</p>
  
  <p>As I said, I'm fairly inexperienced with PHP, as such its very likely something (in fact I'm certain) something is wrong with that code, I've tried a for loop such as;</p>
  
  <pre><code>for($i = 0; $i &lt; $row_count; $i++) {...}
  </code></pre>
  
  <p>but to no avail (it returns something like:</p>
  
  <blockquote>
    <p>["1",[],[],"",null,null,null,{},null,null,null.null[],""..........]</p>
  </blockquote>
  
  <p>Heres the data table layout if it helps;</p>
  
  <pre><code>unitID | unitName | unitType
  
  1 | infantry | Ground &lt;br&gt;
  2 | Tanks | Ground &lt;br&gt;
  3 | Support | Ground &lt;br&gt;
  4 | Artillery | Ground &lt;br&gt;
  . &lt;br&gt;
  .
  </code></pre>
  
  <p>There are 13 items in the table</p>
  
  <p>EDIT:</p>
  
  <p>THis is what I am expecting:</p>
  
  <blockquote>
    <p>[["1", "Infantry","Ground"],["2","Tank","Ground"]....]</p>
  </blockquote>