如何在JS函数上插入DB值



我想将PHP查询数据库中的值插入到.js电子图表页面,如何传输这些数据,以便我可以做图表?

我想计算等待请求,传输到负责创建图形的Javascript

我是一个编程初学者,我喜欢学习,我不是专业人士,我没有在学校学习过。 感谢所有的帮助和理解。

phpquery.php :

<?php
\query get data from bd
$path = $_SERVER['DOCUMENT_ROOT'] . 'distincludes\';
$file = $path . 'db.connect.php';
include($file);
$tec=$_SESSION['nome'];
$permi = $_SESSION['permisson'];
if($permi == "Técnico"){ $sql = "SELECT * FROM npedido WHERE estado = 'Novo' and (tec1 ='$tec' or tec2 ='$tec')";}else if($permi == "Administrador"){ $sql = "SELECT * FROM npedido WHERE estado = 'Novo'";}
$stmt = sqlsrv_query( $conn, $sql);
	 $contador_pedidos_novos = 0;
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) {
$contador_pedidos_novos++;
}


?>
我想把结果放在值里面:"{value:**<--mydata-->**, name:'New'}">

数据加载.js

/*****E-Charts function start*****/
var echartsConfig = function() { 
	
	if( $('#e_chart_3').length > 0 ){
		var eChart_3 = echarts.init(document.getElementById('e_chart_3'));
		var option3 = {
			tooltip : {
				trigger: 'item',
				formatter: "{a} <br/>{b} : {c} ({d}%)",
				backgroundColor: 'rgba(33,33,33,1)',
				borderRadius:0,
				padding:10,
				textStyle: {
					color: '#fff',
					fontStyle: 'normal',
					fontWeight: 'normal',
					fontFamily: "'Roboto', sans-serif",
					fontSize: 12
				}	
			},
			legend: {
				show:true
			},
			toolbox: {
				show : true,
			},
			calculable : true,
			itemStyle: {
				 normal: {
					 shadowBlur: 5,
					 shadowColor: 'rgba(0, 0, 0, 0.5)'
				 }
			},
			series : [
				{
					name:'Advertising',
					type:'pie',
					radius : '60%',
					center : ['50%', '50%'],
					roseType : 'radius',
					color: ['#119dd2', '#d36ee8', '#667add'],
					label: {
						normal: {
							fontFamily: "'Roboto', sans-serif",
							fontSize: 12
						}
					},
					data:[
						{value:25, name:'New'},
						{value:25, name:'Close'},
						{value:50, name:'Hold'},
					].sort(function (a, b) { return a.value - b.value; }),
				},
			],
			animationType: 'scale',
			animationEasing: 'elasticOut',
			animationDelay: function (idx) {
				return Math.random() * 1000;
			}	
		};
		eChart_3.setOption(option3);
		eChart_3.resize();
	}
}
/*****E-Charts function end*****/

答案是在php文件中创建变量,其中数据内容来自查询,然后添加此行'

<script type="text/javascript">var teste = "<?= $teste ?>";</script>

在.js文件中,只需将变量名称添加到数据字段:

<--other code-->
data:[
{value:25, name:teste},
<--other code-->

最新更新