如何在一行Highchart中显示这个MySQL循环?

时间:2011-11-02 06:08:58

标签: php jquery mysql

我正在尝试在Highchart(行)中显示此查询输出。我想知道如何将这个MySQL循环输入Highchart。

<?php
$qu = "SELECT *,COUNT(url) FROM clicks WHERE url='aaaa' GROUP BY date";
        $result = mysql_query($qu) or die(mysql_error());

        while($row = mysql_fetch_array($result)){
        $hits = $row['COUNT(url)'];
        $date = $row['date'];
        }?>

1 个答案:

答案 0 :(得分:1)

也许这会给你一些想法:

$label = array();
while($row = mysql_fetch_array($result))
{
    $label[] = $row["date"];
    $data_count[] = (float)$row["COUNT(url)"];
}

$series = array();
$series[] = array("name"=> 'total', "color" => "#4572a7", "data" => $data_count);

$data = array();
$data["chart"]["renderTo"] = "report";
$data["chart"]["defaultSeriesType"] = "column";
$data["title"]["text"] = "Some Title Here";
$data["series"] = $series;

    $data["xAxis"]["categories"] = $label;
    $data["yAxis"]["allowDecimals"] = true;

header('Content-Type: application/json; charset: utf-8;');
echo json_encode($data);