0

Hi,

I've been searching now for the better part of the weekend but I can't get this to work :-/

I want to use Highcharts pie chart to display data from my mysql table.

I want to count the column 'Types' occurences of the different Types in that column. Each field contains only one word.

The expected output is :['Safari', 8.5], ['Opera', 6.2], ['Others', 0.7] etc

The closest iv'e come is by doing this:

   $result = mysql_query("SELECT Types FROM MCI ".$whereclause." ORDER BY ISF ASC");
    if ($fresult) {
        $kanalfordelning = array();
            while ($row = mysql_fetch_array($fresult)) {
                $Types[]   = $row["Types"];
                }
            }

            <?php  $testisar = array_count_values($kanalfordelning); $festis = json_encode($testisar);?></p>
            <?php echo $festis; ?>

Which outputs {"aDR":8,"SMS":2,"eDR":2} So it's close but Highgraph needs brackets and not curly braces.

Any help would be appreciated!
/Adam

2
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by adishardis
1

There may be a function, but otherwise:

$orig = '{"aDR":8,"SMS":2,"eDR":2}';
$replacements = array("], [", "'", ",", "[", "]");
$find = array(',','"',':','{','}',);

$x =  str_replace( $find, $replacements,$orig);

echo $x;

Edited by diafol

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.