Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 谷歌可视化Api+SQL_Php_Mysql_Api - Fatal编程技术网

Php 谷歌可视化Api+SQL

Php 谷歌可视化Api+SQL,php,mysql,api,Php,Mysql,Api,我想在MySql数据库中创建一些数据的GViz,但我遇到了一些问题 以下是迄今为止的资料来源: <?php $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $int_y_pos = -1; $int_y_step_small = 1; $sql = "SELECT * from table')"; $

我想在MySql数据库中创建一些数据的GViz,但我遇到了一些问题

以下是迄今为止的资料来源:

<?php 
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error 
connecting to mysql'); 
mysql_select_db($dbname); 
$int_y_pos = -1; 
$int_y_step_small = 1; 
$sql = "SELECT * from table')"; 
$sql = mysql_query($sql); 
$rownum = mysql_num_rows($sql); 
?> 
<html> 
  <head> 
    <script type="text/javascript" src="http://www.google.com/jsapi"></ 
script> 
    <script type="text/javascript"> 
      google.load("visualization", "1", {packages: 
["table"]}); 
      google.setOnLoadCallback(drawData); 
      function drawTable() {
        var data = new google.visualization.DataTable(); 
        data.addColumn('string', 'column1'); 
        data.addColumn('string', 'column2'); 
<?php 
echo "     data.addRows($rownum);\n"; 
while($row = mysql_fetch_assoc($sql)) { 
        $int_y_pos += $int_y_step_small; 
        echo "     data.setValue(" . $int_y_pos . ", 0, new column1(" . 
$row['column1']  . "));\n"; 
        echo "     data.setValue(" . $int_y_pos . ", 0, new column2(" . 
$row['column2']  . "));\n";  
} 

?> 
  var table = new google.visualization.Table(document.getElementById('table_div'));
  table.draw(data, {showRowNumber: true});

  google.visualization.events.addListener(table, 'select', function() {
    var row = table.getSelection()[0].row;
    alert('You selected ' + data.getValue(row, 0));
  });
} 
 </script> 
  </head> 
  <body> 
    <div id="table_div" style="width: 940px; height: 240px;"></div> 
  </body> 
</html>
以前集成的任何帮助或示例都将非常有用

谢谢


Gareth

谢谢你的精彩剧本,不管它对我有什么影响

我把它改成这样

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$int_y_pos = -1; 
$int_y_step_small = 1;
$sql = "SELECT * from cache"; 
$sql = mysql_query($sql);
$rownum = mysql_num_rows($sql);
?> 
<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: ['table']});
    </script>
    <script type="text/javascript">
    function drawVisualization() {
      // Create and populate the data table.
      var data = new google.visualization.DataTable();
        data.addColumn('string', 'col1');
        data.addColumn('string', 'col2');
<?php
echo "     data.addRows($rownum);\n";
while($row = mysql_fetch_assoc($sql)) {
        $int_y_pos += $int_y_step_small; 
        echo "     data.setCell(" . $int_y_pos . ", 0,'". $row['col1']  . "');\n"; 
        echo "     data.setCell(" . $int_y_pos . ", 1,'" . $row['col2']  . "');\n"; 
} 

?> 
 // Create and draw the visualization.
      visualization = new google.visualization.Table(document.getElementById('table'));
      visualization.draw(data, null);
    }


    google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="table"></div>                  
  </body>
</html>
这对我很有效: 1.设置表的标题

<?php
    $dataTable = array(
    'cols' => array(
         // each column needs an entry here, like this:
         array('type' => 'string', 'label' => 'Col1'),
         array('type' => 'string', 'label' => 'Col2'),
         array('type' => 'string', 'label' => 'Col3')
    )
);
编码为JSON:

        $json = json_encode($dataTable);?>
然后装载容器并将其显示为表格:

  function drawTable() {
    var data = new google.visualization.DataTable(<?php echo $json; ?>);
    var table = new google.visualization.Table(document.getElementById('your-div-id'));
    table.draw(data);
  }
  function drawTable() {
    var data = new google.visualization.DataTable(<?php echo $json; ?>);
    var table = new google.visualization.Table(document.getElementById('your-div-id'));
    table.draw(data);
  }