dapcigar Posted June 6, 2014 Share Posted June 6, 2014 (edited) Hello all, Am trying to display records from mysql using HIghchart but for some reasons, it is not bringing out any output, please help me look into my codes. :::::::::::::::::::::::::::::::::::::data1.php :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <?php include('mysql_connect.php'); $dept = $_POST['department']; //include('mysql_connect.php'); $stat = 'paid'; $result = mysql_query ("select category, amount, actual from budget where department = '$dept' GROUP BY category ") or die(mysql_error()); $category = array(); $category['name'] = 'category'; $series1 = array(); $series1['name'] = 'actual'; $series2 = array(); $series2['name'] = 'amount'; //$series3 = array(); //$series3['name'] = 'Highcharts'; while($r = mysql_fetch_array($query)) { $category['data1'][] = $r['category']; $series1['data1'][] = $r['actual']; $series2['data1'][] = $r['amount']; // $series3['data'][] = $r['highcharts']; } $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); header("Location: view_dept.php"); mysql_close($con); ?> :::::::::::::::::::::::::::::::::::::::: view_dept.php ::::::::::::::::::::::::::::::::: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { var options = { chart: { renderTo: 'container', type: 'column', marginRight: 130, marginBottom: 25 }, title: { text: 'Chart for Department', x: -20 //center }, subtitle: { text: '', x: -20 }, xAxis: { categories: [] }, yAxis: { title: { text: 'Amount' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { formatter: function() { return '<b>'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y; } }, legend: { layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0 }, series: [] } $.getJSON("data1.php", function(json) { options.xAxis.categories = json[0]['data1']; options.series[0] = json[1]; options.series[1] = json[2]; //options.series[2] = json[3]; chart = new Highcharts.Chart(options); }); }); </script> <script src="http://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/modules/exporting.js"></script> </head> <body> <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div> </body> thanks in advance Edited June 6, 2014 by Maq Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted June 6, 2014 Share Posted June 6, 2014 Based on a cursory look, the two scripts don't appear to be connected. It looks like you're trying to read in the database information in data1.php, then just redirecting to the script which displays the chart. Unfortunately, all the work done in the first script is lost when the redirect happens. If you're trying to use the database information in the chart, you'll need to merge the scripts. Quote Link to comment Share on other sites More sharing options...
maxxd Posted June 6, 2014 Share Posted June 6, 2014 Try removing the header("Location: view_dept.php") line from data1.php. You can close the database connection and then use exit(); to halt script processing. As it stands, by the way, your connection is closed by the page refresh and not the explicit close command. Also, you'll want to start using PDO or mysqli_ - the mysql_ functions have been deprecated for quite some time and are scheduled to be removed in the near-ish future. Quote Link to comment Share on other sites More sharing options...
Maq Posted June 6, 2014 Share Posted June 6, 2014 @OP, please use code tags in the future. Quote Link to comment Share on other sites More sharing options...
dapcigar Posted June 9, 2014 Author Share Posted June 9, 2014 thanks guys but nothing seems to be working. Please, is there anyway i could send just make it work? any syntax that would point me to the right direction? Am a newbie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.