Accepted answer

move the print after the for loop, and don't reinitialize $result to an empty array inside of the loop.


$cc = array();
$cc = count($cb);

one of those lines is redundant (probably the first).


move $result = array(); to occur before the loop, perhaps even before the if-block. you can probably handle the code from there.


highcharts use number data, but your data is a array of strings. so you need to parse it by parsefloat() or use json_encode() with json_numeric_check which allows to return correct json values.


there are two things wrong with your code:

  • you're re-inializing the array on each iteration
  • you're printing the json string on each iteration

what you're seeing as the output is three json strings combined. as there are no line breaks in your code, it'll appear as one big json string.

your code should look like:

$result = array(); // initialize the array
while($ba = mysql_fetch_array($b)) 
    $rows['name'] = $ba[0];
    $rows['data'][] = $ba['jumlah'];
print json_encode($result);

Related Query

More Query from same tag