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

Recommended Answers

All 2 Replies

Member Avatar for diafol

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;

I love you man :) That did it! Thanks a bunch!

Take care
Adam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.