title: How can I build a correct json from mysqli result?
body: <p>I am trying to build a json object from my mysqli result. How do I go about it. At the moment it does not create a json looking object.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$result = $dataConnection-&gt;prepare("SELECT id, artist, COUNT(artist) AS cnt FROM {$databasePrefix}users GROUP BY artist ORDER BY cnt DESC LIMIT 0 , 30");
  $result-&gt;execute();
  if($result-&gt;error)
  {
  die("That didn't work. I get this: " . $result-&gt;error);
  }
  $result-&gt;bind_result($id, $artist, $count);
  $data = array();
  while($result-&gt;fetch()){
  $data[] = '{ id :'.$id.', artist :'.$artist.', count :'.$count.'}';
  }
  echo json_encode($data);
  $dataConnection-&gt;close();
  </code></pre>
  
  <p>I want a data object like:</p>
  
  <pre><code>{"id":"27","artist":"myArtist","count":"29"},....
  </code></pre>