title: php echo json_encode from DB entries -> getting strange format. how to get a proper JSON
body: <p>At the moment i get the following JSON:</p>
  
  <pre><code>["1Sales &amp; Consulting","2Pyments","3Investing","4Financing","5Cross Functional"]
  </code></pre>
  
  <p>but i would like to have a proper JSON like:</p>
  
  <pre><code>[{"id":1, "name": "Sales &amp; Consulting"}{"id": 2, "name": "Pyments"}{"id": 3, "Investing"}{"id": 4, "name": "Financing"}{"id": 5, "name": "Cross"}] 
  </code></pre>
  
  <p>The code i used to generate the first output is:</p>
  
  <pre><code>&lt;?php
  define('servername','localhost');
  define('username','root');
  define('password','');
  define('dbname','integration');
  // Create connection
  $conn = new mysqli(servername, username, password, dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  $sql = "SELECT id, name FROM capability_level1";
  $result = $conn-&gt;query($sql);
  $test = array();
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
          $test[] = $row["id"] . $row["name"];
      }
      echo json_encode($test);
  } else {
      echo json_encode("0 results");
  }
  $conn-&gt;close();
  ?&gt;
  </code></pre>
  
  <p>what do i have to change? this echo is needed to pass to ajax in a second step</p>