<script>
<?php
unset($data0);
unset($data1);
unset($data2);
$sth = $dbh->prepare("
SELECT a, b, c
FROM t
");
$sth->execute();
?>
Morris.Line({
element: 'morris-line-chart',
data: [
<?php
while ($row = $sth->fetch()) { ?>
{ m: '<?php echo $row['0']; ?>', a: <?php echo $row['1']; ?>, b: <?php echo $row['2']; ?> },
<?php } ?>
],
xkey: 'm',
xLabels: 'month',
ykeys: ['a', 'b'],
labels: ['2014', '2015']
});
</script>
Is there a cleaner way to write it, especially the PHP echoing to create the JavaScript?