Hi everyone, I have some questions,
help me advice.
in the FILE1.php with java scrip I put up some php code in a head of file.
my task is that the user would have seen a drop-down box, choose the item he wants and clicks on it, but all the processing took place in the FILE2.php
How can I send a value from FILE1.php to the FILE2.php ? but it must be while AJAX call this FILE2.php in other case it will be without my parameters from FILE1.php ?
It must be somethind like that function drawBasic(){
var jsonData = $.ajax({
url: "FILE2.php:getDataString($var1, $var2...etc)", // Function from FILE2.php
dataType: "json",
async: false
}).responseText;
---------------------------------------------------------------------------------
FILE1.PHP
<?php
//SQL Query for Dropdown-List in the same page
//FORM must be send via $_SERVER["PHP_SELF"]
FILE1.PHP
?>
<script type="text/javascript" src="
https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="//
ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function drawBasic(){
var jsonData = $.ajax({
url: "FILE2.php",
dataType: "json",
async: false
}).responseText;
var data = new google.visualization.DataTable(jsonData);
var options = {
hAxis: {
title: 'Weeks'
},
vAxis: {
title: 'Value'
},
};
var chart1 = new google.visualization.LineChart(document.getElementById('chart_div'));
chart1.draw(data, options);
}
google.charts.load('current', {packages: ['corechart', 'line']});
google.charts.setOnLoadCallback(drawBasic);
</script>
<table border="0" align="center">
<tr>
<td> <div id="chart_div" style="width: 850px; height: 500px;"></div> </td>
</tr>
</table>
---------------------------------------------------------------------------------------------------------------------
FILE2.PHP
<?php
$db = mysqli_connect("localhost","root","p@$WorDt","db");
function getDataString($manager_group){
global $db;
$i = 0;
$query="select date, sum(salary) as sum_gr from manager where manager_group=$manager_group";
$res = mysqli_query($db,$query);
$data = '{"cols": [';
$data .= '{"id":"","label":"DATUM","type":"number"},';
// $data .= '{"id":"","label":"SALARY","type":"number"}';
$data .= '{"id":"","label":"'GROUP'","type":"string"}';
$data .= '],"rows": [';
while($row = mysqli_fetch_assoc($res)){
$data .='{"c":[
{"v":"'.$row[date].'","f":null},
{"v":"'.$row['sum_gr'].'","f":null}
]},';
}
$data=rtrim($data,',');
$data .=']}';
return $data;
}
echo getDataString();
?>