大家好我是新手我有一个关于如何将输入形式变为请求URL的问题
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>中国武夷 000797 - 历史大单</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var options = {
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
},
title: {
text: '中国武夷 000797 历史大单 from 2016-03-14'
},
tooltip: {
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage,2) +' %';
}
},
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,0) +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'BigVolume share',
colors: ['#DD5044','#17A05D','#FFCE43'],
data: []
}]
}
$jsonurl="000797vol400piedata.php?df=";
$.getJSON($jsonurl, function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options);
});
$('#button').click(function() {
$jsonurl="000797vol400piedata.php?df=";
$.getJSON($jsonurl2, function(json) {
options.series[0].data = json;
chart = new Highcharts.Chart(options).redraw();
});
});
// window.setInterval(function(){
// $.getJSON("000797datapievol400.php", function(json) {
// options.series[0].data = json;
// chart = new Highcharts.Chart(options);
// });
//}, 3000);
});
</script>
<!-- <script src="http://code.highcharts.com/highcharts.js"></script> -->
<script src="../../stock/js/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</head>
<body>
<div id="container" style="min-width: 280px; height: 230px; margin: 0 auto"></div>
<form name="form" action="<?php $jsonurl2 = $jsonurl.$_GET['df'];?>" method="GET">
<input type="text" name="df" value="2016-4-1" />
<input type="button" id="button" value="Start Date" />
</form>
</body>
</html>
000797vol400piedata.php代码是
<?php
$con = mysql_connect("localhost","tushare","tusharetushare");
$df = htmlspecialchars($_GET["df"]) ;
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("stockhistory", $con);
$resultx = mysql_query("select type,sum(volume) from `vol400-000797` where type='买盘' and date BETWEEN '$df' AND current_date()");
$rowsx = array();
while($r = mysql_fetch_array($resultx)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rowsx,$row);
}
$resulty = mysql_query("select type,sum(volume) from `vol400-000797` where type='卖盘' and date BETWEEN '$df' AND current_date()");
$rowsy = array();
while($r = mysql_fetch_array($resulty)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rowsy,$row);
}
$resultz = mysql_query("select type,sum(volume) from `vol400-000797` where type='中性盘' and date BETWEEN '$df' AND current_date()");
$rowsz = array();
while($r = mysql_fetch_array($resultz)) {
$row[0] = $r[0];
$row[1] = $r[1];
array_push($rowsz,$row);
}
$rows=array_merge($rowsx,$rowsy,$rowsz);
print json_encode($rows, JSON_NUMERIC_CHECK);
mysql_close($con);
?>
我认为表单代码有问题 单击按钮
时,$ jsonurl2无法获取值
答案 0 :(得分:1)
您的表单操作必须是000797vol400piedata.php,因此您的表单应如下所示:
.css()
并在000797vol400piedata.php
使用$ _GET ['df']得到df值:
<form name="form" action="000797vol400piedata.php" method="GET">
<input type="text" name="df" id="df" value="2016-4-1" />
<input type="submit" name="submit" value="Start Date" />
</form>
在你的情况下,为了在javascript中使用PHP变量,你应该考虑使用ajax。所以你的代码必须是:
$df = $_GET['df'];
停止使用mysql扩展,使用PDO或mysqli。
答案 1 :(得分:1)
请查看代码的这一行
<form name="form" action="<?php $jsonurl2 = $jsonurl.$_GET['df'];?>" method="GET">
在表单的action属性中
action="<?php $jsonurl2 = $jsonurl.$_GET['df'];?>"
替换为
action="000797vol400piedata.php"
也在表格内,在这一行
<input type="button" id="button" value="Start Date" />
在
中更改<input type="submit" id="button" value="Start Date" />
并且您的表单必须如下所示
<form name="form" action="000797vol400piedata.php" method="GET">
<input type="text" name="df" value="2016-4-1" />
<input type="submit" id="button" value="Start Date" />
</form>
在你的000797vol400piedata.php
中,你可以这样做,以获得你传递的var的值。这只是如何接收表单发送的值的示例。以此为例进行编码。
$value = $_GET['df'];
echo "$df";