简体   繁体   English

如何从表单输入变量从另一个PHP更新图表?

[英]How to update the chart from another php with input the variable from the form?

I am creating a report which can display a chart dynamically when i modify the variable, what i do will follow the below step: 1. input the variable date in the index.html form and pass the start date and end date to the get_data.php 2. get_data.php will base on the post variable date and run the sql and get the array. 我正在创建一个报告,当我修改变量时可以动态显示图表,我将执行以下步骤:1.在index.html表单中输入变量日期,并将开始日期和结束日期传递给get_data。 php 2. get_data.php将基于post变量date并运行sql并获取数组。 3. base on the array from get_data.php will back to the index.html and display as a chart. 3.基于从get_data.php数组将返回到index.html并显示为图表。 All this will only happen in the index.html, won't go to get_data.php 所有这些都只会在index.html中发生,而不会进入get_data.php

The error I am facing is that I can run the get_data.php correctly but the result can't pass back to the index.html and display correctly. 我面临的错误是我可以正确运行get_data.php,但结果无法传递回index.html并正确显示。 My code as below: 我的代码如下:

index.html index.html

 <script type="text/javascript" src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="https://canvasjs.com/assets/script/canvasjs.min.js"></script> <script type="text/javascript"> window.onload = function () { var chart = new CanvasJS.Chart("chartContainer", { theme: "theme2", title: { text: "User" }, data: [ { type: "column", dataPoints: [ <?php require('last_month_report.php'); echo str_replace("}{", "},{", $dataset);?> ] } ] }); chart.render(); $("#apply").click(function() { var data = $("#report :input").serializeArray(); $.post( $("#report").attr("action"), data, function(updatedata) { dataPoints.push(updatedata); chart.render(); updateChart(); }); }); $("#report").submit( function() { return false; }); }; </script> 
 <!DOCTYPE html> <html> <body> <form action="get_data.php" method="post" id="report"> <input type="date" name="start_date" id="start_date"> <input type="date" name="end_date" id="end_date"> <button id="apply" type="submit">Apply</button> </form> <div id="chartContainer"></div> </body> </html> 

get_data.php get_data.php

 <?php $start_date = $_POST[start_date]; $end_date = $_POST[end_date]; $link=mysql_connect('localhost','root','123'); mysql_set_charset('utf8', $link); $selectdb=mysql_select_db('test',$link); $sql="SELECT date, user FROM `report` WHERE date >= '$start_date' and date <= '$end_date'"; $result = mysql_query($sql, $link); $init=0; $num=mysql_num_rows($result); while ($init < $num) { $row=mysql_fetch_array($result); $dataset = $dataset . '{label: "' . $row[date] . '",y: ' . $row[date] . '}'; $init++; } ?> 

these wont work 这些不会工作

     $start_date = $_POST[start_date];
     $end_date = $_POST[end_date];

missing " " should be 缺少" "应为

     $start_date = $_POST["start_date"];
     $end_date = $_POST["end_date"];

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

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