score:2

Accepted answer

So in your php file....

Add a line at the bottom that converts the table to json data. And give it a variable...

$table = array();  
 while($row = mysqli_fetch_assoc($result) )  
 {

   $value=$row['value'];
   $date=$row['date'];

   $table[$value]=$date;

 }

 $jsondata = json_encode($table);

Then in your other file.... echo that variable into your data object, in the javascript. Remember to remove that whole random number generating function...(its just an example)

Echoing PHP into javascript is definitely not considered good practice though. And it would be better to actually do an ajax call to your php file, and insert like that....I'll also show you how to do ajax.

  <?php include 'test.php';  ?>

    ... 

   data: [<?php echo $jsondata;?>], //remove that function that was here..
   // it was just to generate random numbers for the demo
   ....
   }

EDIT / UPDATE For ajax...

So for ajax...instead of assigning a variable to $jsondata. Just return it like so...(in your PHP file)

 return json_encode($table);

Then for this way....you dont include('test.php') like you did before. Instead you just have this script inside your $(document).ready(function(){....

$.getJSON('test.php', function(myJSON) {

 //and inside this function you put your highcharts stuff...
 //remove that function() that generates random data
 // And you will put the 'myJSON' return object inside the 'data':[] array...
 // Provided you have structured your data correctly for highcharts, it should work...
 //  If not.... it'll be a start, and you're well on your way to debugging it

}

Related Articles