简体   繁体   English

如何在JS函数上插入数据库值

[英]how to insert DB values on JS function

I want to insert values ​​from PHP query DB to .js echart page, how do I transfer this data, so I can do the graph? 我想将PHP查询数据库中的值插入.js echart页面中,该如何传输这些数据,以便进行图形处理?

I want to count the waiting requests, transport to the Javascript responsible for the creation of the graph 我要计算等待的请求,传输到负责创建图的Javascript

I'm a programming beginner and I enjoy learning, I'm not a professional and I did not study it at school. 我是一名编程初学者,喜欢学习,我不是专业人士,并且没有在学校学习。 Thanks for all the help and understanding. 感谢您的所有帮助和理解。

phpquery.php : phpquery.php:

 <?php \\\\query get data from bd $path = $_SERVER['DOCUMENT_ROOT'] . '\\dist\\includes\\\\'; $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++; } ?> 
i want to put the result inside value: " {value:**<--mydata-->**, name:'New'} " 我想将结果放入值内:“ {value:**<--mydata-->**, name:'New'}

dataload.js dataload.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*****/ 

the answer is in the php file create variable whit the datacontent from query then add this line` 答案是在php文件中创建变量,从查询中获取数据内容,然后添加此行`

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

on .js file just add the variable name to data field: 在.js文件上,只需将变量名称添加到数据字段:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM