我有两个文件 1. Analytics.php 2. data.php
Analytics.php 代码
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
/*tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Math.round(this.percentage) +' %';
}
},*/
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 1) +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Documents',
data: []
}]
}
$.getJSON("data.php", function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
});
html代码:
<form method="post" name="havoc" >
Search <input type="text" placeholder="Eg: Ronnie" name="authname_sa" value="">
<input type="submit" name="search_authanalysis_sa" value="Search">
</form>
<?php
if(isset($_POST['search_authanalysis_sa'])){
$auth_sa = mysql_real_escape_string($_POST['authname_sa']);
}
?>
2. data.php Code
<?php
include 'connect.php';
$df = $_POST['authname_sa'];
$result = mysql_query("SELECT subj_area, documents, auth_name FROM subj_area WHERE auth_name='$df'");
$rows = array();
while($r = mysql_fetch_array($result)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rows,$row);
}
print json_encode($rows, JSON_NUMERIC_CHECK);
这里的图表工作正常。但问题在于 data.php 文件中的 php 变量 $df 具有一些由表单发布的值。但是当我尝试使用 that is where 子句时,它没有得到那个值。
但如果手动输入值,如 $result = mysql_query("SELECT subj_area, documents, auth_name FROM subj_area WHERE auth_name='Ronnie'");
如上所示,如果我直接将值输入为 Ronnie,那么它就可以工作了。实际上是什么问题?请帮忙。