score:1

Accepted answer

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

Also...

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

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

score:1

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'];
    array_push($result,$rows);
}
print json_encode($result);

score:0

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

score:0

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.


Related Articles