title: How can I encode data to json?
body: <p>I want to encode data to json. Now by bottom code I have id and product title, but I want add another data like cost. How can I do that?</p>
  
  <pre><code>&lt;?php
  
  $sql = 'SELECT id,title,cost,cat
          FROM prodcts_df';
  $q = $db-&gt;query($sql);
  $q-&gt;setFetchMode(PDO::FETCH_ASSOC);
  
  ?&gt;
  
   &lt;?php
   while ($r = $q-&gt;fetch()): ?&gt;
      &lt;?php $myJson-&gt;$r['id']= $r['title'];?&gt;
   &lt;?php endwhile; ?&gt;
  
  &lt;?php echo json_encode($myJson); ?&gt;
  </code></pre>