4 Replies - 899 Views - Last Post: 09 January 2013 - 09:31 PM Rate Topic: -----

#1 wkwan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-December 11

Google organizational charts

Posted 08 January 2013 - 02:10 AM

Hi I am trying to build an organizational chart using google's tool.
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>



Is This A Good Question/Topic? 0
  • +

Replies To: Google organizational charts

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Google organizational charts

Posted 08 January 2013 - 02:19 AM

Well, where are you calling the function drawChart() ?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 wkwan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-December 11

Re: Google organizational charts

Posted 08 January 2013 - 02:40 AM

it appears i am missing the architecture required to use php (apache)
maybe that is why :smile2:
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2834
  • View blog
  • Posts: 9,740
  • Joined: 08-August 08

Re: Google organizational charts

Posted 09 January 2013 - 08:08 PM

Are you saying that the php code does not execute? Another possibility is that it is executing, but not when you think it should. The PHP code is executed on the server before the html and javascript is fully processed by the browser.
Was This Post Helpful? 0
  • +
  • -

#5 wkwan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-December 11

Re: Google organizational charts

Posted 09 January 2013 - 09:31 PM

View Postraghav.naganathan, on 08 January 2013 - 02:19 AM, said:

Well, where are you calling the function drawChart() ?

regards,
Raghav


drawChart() is called from :
google.setonloadCallback(drawChart);
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1