<?php
$connect = mysqli_connect("localhost", "root", "123456", "testing");
$query="select uniqueid, managerid from employees";
/*
# Collect the results
while($obj = mysql_fetch_object($query)) {
$arr[] = $obj;
}
# JSON-encode the response
$json_response = json_encode($arr);
// # Return the response
echo $json_response;
*/
$result = mysqli_query($connect, $query);
?>
<html>
<head>
<script type='text/javascript' src='jquery-1.6.2.min.js'></script>
<script type='text/javascript'>
google.load('visualization', '1', { packages: ['orgchart'] });
google.setOnLoadCallback(drawChart);
function drawChart()
{
var data = google.visualization.arrayToDataTable([
['UniqueId', 'ManagerId'],
<?php
while($row = mysqli_fetch_array($result))
{
echo "['".$row[1]."', ".$row[0]."],";
}
?>
]);
var data = new google.visualization.DataTable(jsonData);
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows([
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>
------------------------------------------------
database table name employees
UniqueId ManagerId Name
1 0 ABC
2 1 DEF
3 1 GHI
4 2 JKL
5 2 MNO