javascript - Get data highchart from php table -


i want show every row data table highchart, how can show data using php javascript foreach row?

<script>     series: [{           name: 'mie instan',           data: [<?php foreach ($query $row){echo $row['mie'];}]      }, {           name: 'beras',           data: [<?php foreach ($query $row){echo $row['beras'];}]      }, {           name: 'telur',           data: [<?php foreach ($query $row){echo $row['telur'];}]      }] </script> 

what do, in order highcharts data arranged array of numerical values, use php array_push , php foreach sort data in 3 different php arrays.

<?php // declare 3 new arrays. $mie=[]; $beras=[]; $telur=[];  // fill arrays database values foreach ($query $row){     array_push($mie, $row['mie']);     array_push($beras, $row['beras']);     array_push($telur, $row['telur']); } ?> 

then use arrays produce string of "coma separated values" in highcharts script, using php join, this:

<script>     series: [{           name: 'mie instan',           data: [<?php echo join(",", $mie); ?>]      }, {           name: 'beras',           data: [<?php echo join(",", $beras); ?>]      }, {           name: 'telur',           data: [<?php echo join(",", $telur); ?>]      }] </script> 

hoping helps...
;)


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -