以下代码将通过url:GETDATA.PHP显示来自数据库的数据,并在工作中显示我的数据。但我的问题是,如何传递$ iddoc = $ _GET [' id'];到我的GETDATA.PHP..so它可以根据获取文档ID创建图表..
Histogram.php
<?php
session_start();
if(isset($_SESSION['idmember'])){
$idmembersession = $_SESSION['idmember'];
$iddoc = $_GET['id'];
include'configure.php';
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
HISTOGRAM SAM
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
function drawVisualization() {
var jsonData=null;
var json = $.ajax
({
url:"getdata.php", // make this url point to the data file
dataType: "json",
async: false,
success: (
function(data) {
jsonData = data;
var data = new google.visualization.DataTable(jsonData);
var options = {
title: 'SAM Histogram Results',
hAxis: {title: 'Sustainability Percentage'},
titleTextStyle: {color: 'black'},
hAxis: { ticks:[1,2,3,4,5,6,7,8,9,10,11,12,
13,14,15,16,17,18,19,20,21,22,23,24] },
}
var chart = new google.visualization.ColumnChart
(document.getElementById('visualization')).
draw(data,options);
})
}).responseText;
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body>
<div id="visualization" style="width: 1300px; height: 800px;"></div>
</body>
</html>
访问getdata.php
<?php
session_start();
if(isset($_SESSION['idmember'])){
$idmembersession = $_SESSION['idmember'];
$iddoc = $_GET['id'];
include 'configure.php';
$query = "SELECT * FROM criteria_match
where document = '$iddoc' and idmember ='$idmembersession'";
$sql_query = mysql_query($query) or die('Error 3 :'.mysql_error());
$table = array();
$table['cols'] = array(
array('label' => 'criteria', 'type' => 'number'),
array('label' => 'percentage', 'type' => 'number')
);
$rows = array();
while($r = mysql_fetch_assoc($sql_query)) {
$temp = array();
$temp[] = array('v' => (int)$r['criteria']);
$temp[] = array('v' => (float)$r['percentage']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');
echo $jsonTable;
}
?>
答案 0 :(得分:0)
将该变量作为ajax中的数据值回显:
...
url:"getdata.php", // make this url point to the data file
type: "POST" // or GET, depends on your choice
data {
iddoc: '<?php echo htmlspecialchars($iddoc); ?>'
},
dataType: "json",
async: false,
...
在Getdata.php
中,您将获得$_POST["iddoc"]
。
我假设您正确地获得了$_GET['id']
。