1
我需要将一个变量从$ _GET ['variableID'],在Google图表脚本之前传递给目标页面PHP,以确定我想要的客户端做查询。我怎么能? (注意:我不是JavaScript中的天才)。非常感谢你!!将Google Chart脚本中的变量传递给MySql PHP
这是我定义
/* Get data from the database */
function getData() {
jQuery.ajax({
url: 'get.php',
type: 'GET',
dataType: 'json',
mimeType: 'multipart/form-data',
contentType: false,
cache: false,
processData: false,
success: function(data, jqXHR) {
if(data == "null") {
// just in case
} else {
drawGraph(data);
}
},
error: function(textStatus) {
console.log(" error. damm. ");
}
});
}
/* Initialization of Google Charts API */
google.load("visualization" , "1", { packages: [ "corechart" ] });
google.setOnLoadCallback(getData);
/* Chart to render time-user graphs */
function drawGraph(data) {
for(var i = data.length; i > 0; i--) {
data[i] = data[i - 1];
}
data[0] = [ 'Data', 'Comandes' ];
console.log(data);
var chartData = google.visualization.arrayToDataTable(data);var options = {
title: '','legend':'none','chartArea': {'width': '100%', 'height': '80%'},
backgroundColor: {
stroke: '#a5a5a5',
strokeWidth: 1
},
hAxis: {
format: 'M/d/yy',
gridlines: {count: 15}
},
vAxis: {
gridlines: {color: '#d0d0d0'},
minValue: 0
}
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(chartData , options);
}
的chart.js之这是get.php(特别注意WHERE idclient = GET variableID)
include('lib/connection.php');
if($_GET) {
$query = "select DATE(data), COUNT(*)
from smarty_pedidos **WHERE idclient=GET variableID**
group by DATE(data)";
$result = mysql_query($query);
$rows = array();
while($row = mysql_fetch_array($result)) {
$rows[] = array('0' => $row['0'] , '1' => $row['1']);
}
//print json_encode($rows);
print json_encode($rows, JSON_NUMERIC_CHECK);
}
不起作用,非常感谢 –