I want to get the data from MSSQL and then show the chart on the webpage.
This is what I have so far but the page is empty when i try to run it.
if anyone can take a look and point out what is the problem, it would be very helpful.
I am pretty sure the problem is with the querying of SQL through the PHP. The google part should not be the problem.
<html>
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setonloadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Manager');
data.addcolumn('string', 'tooltip');
data.addRows([
<?php
$myServer = "localhost";
$myUser = "user";
$myPass = "******";
$myDB = "testJG";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT GOOGNO,GOOGUP";
$query .= "FROM GOG1 ";
$result = mssql_query("SELECT GOOGNO,GOOGUP FROM GOG1");
//execute the SQL query and return records
$output = array();
while($row = mssql_fetch_array($result)) {
// create a temp array to hold the data
$temp = array();
// add the data
$temp[] = '"' . $row['GOOGNO'] . '"';
$temp[] = '"' . $row['GOOGUP'] . '"';
// implode the temp array into a comma-separated list and add to the output array
$output[] = '[' . implode(', ', $temp) . ']';
}
// implode the output into a comma-newline separated list and echo
echo implode(",\n", $output);
mysql_close($con);
?>
]);
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
chart.draw(data, {allowHtml:true});
}
</script>
</head>
<body>
<div id='chart_div'></div>
</body>
</html>

New Topic/Question
Reply



MultiQuote





|