php - Combine Google_Org_Chart with Mysql -


im new @ php..

i have task make organizational chart (just google chart) rendered mysql, follows org chart

and database: sql

here code google chart.. `

        <!--         free copy , use sample in accordance terms of         apache license (http://www.apache.org/licenses/license-2.0.html)         -->          <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">         <html xmlns="http://www.w3.org/1999/xhtml">           <head>             <meta http-equiv="content-type" content="text/html; charset=utf-8"/>             <title>               google visualization api sample             </title>             <script type="text/javascript" src="http://www.google.com/jsapi"></script>             <script type="text/javascript">               google.load("visualization", "1", {packages: ["orgchart"]});             </script>             <script type="text/javascript">               function drawvisualization() {  // block of codes below want change , render mysql, unfortunately dont know how      // create , populate data table.                 var data = google.visualization.arraytodatatable([                   ['name', 'manager', 'tooltip'],                   ['mike', null, 'the president'],                   [{v: 'jim', f: 'jim<br/><font color="red"><i>vice president<i></font>'}, 'mike', null],                   ['alice', 'mike', null],                   ['bob', 'jim', 'bob sponge'],                   ['carol', 'bob', null]                 ]);                  // create , draw visualization.                 new google.visualization.orgchart(document.getelementbyid('visualization')).                     draw(data, {allowhtml: true});               }                google.setonloadcallback(drawvisualization);             </script>           </head>           <body style="font-family: arial;border: 0 none;">             <div id="visualization" style="width: 300px; height: 300px;"></div>           </body>         </html> 

anybody knows something?? appreciated.. thanks..

regards, aryo

you can try this:

<?php // set database connection parameters $databasename = '<name of database>'; $username = '<user>'; $password = '<password>'; try {     $db = new pdo("mysql:dbname=$databasename", $username, $password); } catch (pdoexception $e) {     echo $e->getmessage();     exit(); } $db->setattribute(pdo::attr_errmode, pdo::errmode_exception);  $query = $db->prepare('select id, nama, parent_id tbl_dummy'); $query->execute(); $results = $query->fetchall(pdo::fetch_assoc);  $flag = true; $table = array(); $table['cols'] = array(     array('label' => 'id', 'type' => 'number'),     array('label' => 'name', 'type' => 'string'),     array('label' => 'parent id', 'type' => 'number') ); $table['rows'] = array();  foreach ($results $row) {     $temp = array();     $temp[] = array('v' => (int) $row['id']);     $temp[] = array('v' => $row['nama']);     $temp[] = array('v' => (int) $row['parent_id']);     $table['rows'][] = array('c' => $temp); } $jsontable = json_encode($table); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8"/>         <title>         google visualization api sample         </title>         <script type="text/javascript" src="http://www.google.com/jsapi"></script>         <script type="text/javascript">             function drawvisualization() {                 // create , populate data table.                 var data = new google.visualization.datatable(<?php echo $jsontable; ?>);                  // create , draw visualization.                 new google.visualization.orgchart(document.getelementbyid('visualization')).                 draw(data, {allowhtml: true});             }              google.setonloadcallback(drawvisualization);             google.load('visualization', '1', {packages: ['orgchart']});         </script>     </head>     <body style="font-family: arial;border: 0 none;">         <div id="visualization" style="width: 300px; height: 300px;"></div>     </body> </html> 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -