求助,如何让php数据在JS代码中循环输出。
<?phpinclude("inc/auth.php");include_once("inc/utility_all.php");include_once("inc/ut...
<?php
include("inc/auth.php");
include_once("inc/utility_all.php");
include_once("inc/utility_org.php");
$query1="select * from bchaoraom where ctype=0 ORDER BY `bchaoraom`.`cdata` asc ";
$cursor= exequery($connection,$query1);
while($ROW=mysql_fetch_array($cursor))
{
$ctype=$ROW['ctype'];//类型
$cdata=$ROW['cdata'];//时间
$yue=substr($cdata,6);
$nian=substr($cdata,0,4);
echo $nian;
$cjiage=$ROW['cjiage'];//价格
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: '缠绕膜统计趋势报表'
},
subtitle: {
text: 'An example of irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%Y年%M月',
year: '%Y年'
}
},
yAxis: {
title: {
text: '价格(元)'
},
min: 0
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y年%m月', this.x) +': '+ this.y +' 元';
}
},
series: [{
name: '市场缠绕膜价格',
// Define the data points. All series have a dummy year
// of 1970/71 in order to be compared on the same x axis. Note
// that in JavaScript, months start at 0 for January, 1 for February etc.
data: [
[Date.UTC(2013,1),17 ],
[Date.UTC(2013,2),18 ],
[Date.UTC(2013,3),17 ],
[Date.UTC(2013,4),19 ],
[Date.UTC(2013,5),20 ],
]
}, ]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html> 展开
include("inc/auth.php");
include_once("inc/utility_all.php");
include_once("inc/utility_org.php");
$query1="select * from bchaoraom where ctype=0 ORDER BY `bchaoraom`.`cdata` asc ";
$cursor= exequery($connection,$query1);
while($ROW=mysql_fetch_array($cursor))
{
$ctype=$ROW['ctype'];//类型
$cdata=$ROW['cdata'];//时间
$yue=substr($cdata,6);
$nian=substr($cdata,0,4);
echo $nian;
$cjiage=$ROW['cjiage'];//价格
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Highcharts Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'spline'
},
title: {
text: '缠绕膜统计趋势报表'
},
subtitle: {
text: 'An example of irregular time data in Highcharts JS'
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: { // don't display the dummy year
month: '%Y年%M月',
year: '%Y年'
}
},
yAxis: {
title: {
text: '价格(元)'
},
min: 0
},
tooltip: {
formatter: function() {
return '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%Y年%m月', this.x) +': '+ this.y +' 元';
}
},
series: [{
name: '市场缠绕膜价格',
// Define the data points. All series have a dummy year
// of 1970/71 in order to be compared on the same x axis. Note
// that in JavaScript, months start at 0 for January, 1 for February etc.
data: [
[Date.UTC(2013,1),17 ],
[Date.UTC(2013,2),18 ],
[Date.UTC(2013,3),17 ],
[Date.UTC(2013,4),19 ],
[Date.UTC(2013,5),20 ],
]
}, ]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>
</body>
</html> 展开
1个回答
展开全部
和输出普通的html没有任何区别,例如
<?php $a = array(1,2,3);?>
<script>
<?php foreach($a as $value):?>
alert('<?php echo $value?>');
<?php endforeach;?>
</script>
追问
我是要将php数据写入
data: [
[Date.UTC(2013,1),17 ],
[Date.UTC(2013,2),18 ],
[Date.UTC(2013,3),17 ],
[Date.UTC(2013,4),19 ],
[Date.UTC(2013,5),20 ],
]
里面,但是我加php代码的时候就报错了
追答
贴出来看看啊,应该是你的具体代码出错了,不是因为不允许这样写。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询