gpt4 book ai didi

javascript - 将变量从 Google Chart 脚本传递到 MySql PHP

转载 作者:行者123 更新时间:2023-11-28 05:33:20 24 4
gpt4 key购买 nike

我需要在Google图表脚本之前从$_GET['variableID']传递一个变量,然后传递到目标页面PHP以确定我想要哪个客户端进行查询。我怎么能? (注意:我不是 javascript 天才)。非常感谢!!

这是我定义的chart.js

/* 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 );
}

这是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);
}

最佳答案

在 ajax 调用中,将变量添加到 url...

jQuery.ajax({
url: 'get.php?variableID=variableVALUE',
...

然后在 php 代码中,使用 $_GET['variableID']

$query = "select DATE( data ), COUNT(*)
from smarty_pedidos WHERE idclient=$_GET['variableID']
group by DATE( data )";

关于javascript - 将变量从 Google Chart 脚本传递到 MySql PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39536108/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com