包含来自MySQL的数据的高图表

时间:2016-05-10 11:00:57

标签: php mysql arrays session highcharts

我目前正在创建一个资金管理系统,其想法是用户输入数据并通过高图表区域图表进行可视化。我目前有一个从数据库收集数据的工作版本,这是通过以下教程完成的:https://blueflame-software.com/area-chart-with-data-from-mysql-using-highcharts/

此代码设置为从数据库接收4个数据,月份,收入,支出,订阅,内部收入/ exp / sub只是数字。我希望更改数据库,以便Income / exp / sub全部在Trans_Type的1标题下,并且每个数量都在Trans_Amount下。

我的问题是如何更改下面示例中给出的实际PHP代码以适合MySQL查询,例如“SELECT Month, Trans_Amount, Trans_Type 'Income', 'Expenditure', 'Subscriptions' FROM transactions WHERE UserID=".$_SESSION['user'])

My Current working PHP:

$query = mysql_query("SELECT Month, Income, Expenditure , Subscriptions FROM     transactions WHERE UserID=".$_SESSION['user']);

$category = array();
$category['name'] = 'Month';

$series1 = array();
$series1['Amount'] = 'Income';

$series2 = array();
$series2['name'] = 'Expenditure';

$series3 = array();
$series3['name'] = 'Subscriptions';


while($r = mysql_fetch_array($query)) {
$category['data'][] = $r['Month'];
$series1['data'][] = $r['Income'];
$series2['data'][] = $r['Expenditure'];
$series3['data'][] = $r['Subscriptions'];   
}

$result = array();
array_push($result,$category);
array_push($result,$series1);
array_push($result,$series2);
array_push($result,$series3);


print json_encode($result, JSON_NUMERIC_CHECK);

mysql_close($con);

0 个答案:

没有答案