Generate line chart from SQL database output using Morris
I like to keep the Javascript in one echo at the bottom, like this:

&lt;?php

unset($data0);
unset($data1);
unset($data2);

$sth = $dbh-&gt;prepare("SELECT a, b, c FROM t");
$sth-&gt;execute();

$data = '';
while ($row = $sth-&gt;fetch(FETCH_ASSOC)) { 
  extract($row);
  $data .= "{ m: '$c', a: $a, b: $b },".PHP_EOL;
} 

echo "&lt;script&gt;
Morris.Line({
  element: 'morris-line-chart',
  data: [$data],
  xkey: 'm',
  xLabels: 'month',
  ykeys: ['a', 'b'],
  labels: ['2014', '2015']
});
&lt;/script&gt;";


I had to make the assumptions that you're using PDO and that $c is your m in the morris line.