gpt4 book ai didi

javascript - 谷歌图表 : how to hold and pass _GET ID to url:

转载 作者:行者123 更新时间:2023-11-30 00:32:18 26 4
gpt4 key购买 nike

下面的代码将通过 url: GETDATA.PHP 显示数据库中的数据,在作品中并显示我的数据。但我的问题是,如何传递 $iddoc = $_GET['id'];到我的 GETDATA.PHP..这样它就可以根据获取文档 ID 创建图表..

直方图.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>

获取数据.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;
}
?>

最佳答案

将该变量回显为 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']

关于javascript - 谷歌图表 : how to hold and pass _GET ID to url:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22422214/

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