title: MySQL data to JSON via PHP
body: <p>Basically idea is to grab data from MySQL table and transform it to JSON.</p>
  
  <p>This is how database table looks:</p>
  
  <p><img src="https://i.stack.imgur.com/FdxPQ.jpg" alt="enter image description here"></p>
  
  <p>And this how should output be:</p>
  
  <pre><code>[
     {"group1":[
                 {"val":"somevalue"},
                 {"val":"somevalue"}
               ]
     },
     {"group2":[
                 {"val":"somevalue"},
                 {"val":"somevalue"}
               ]
     },
     {"group3":[
                 {"val":"somevalue"}
               ]
     }
  ]
  </code></pre>
  
  <p>My PHP script looks like this, for now:</p>
  
  <pre><code>$arr = [];
  $result = mysql_query("SELECT * FROM thetable WHERE section='sect1'");
  while($row = mysql_fetch_array($result))
  {
    // ???
  }
  
  echo json_encode($arr);
  </code></pre>
  
  <p>My main issue is how to output/sort data in "groups".</p>
  
  <p>Thanks for your help!</p>