I would really appreciate if someone could help me out. I did try hard to find a solution but to no avail due to my limited skills. Here is the scenario: I have got a python script that outputs temperature, pressure and humidity from a sensor connected to my Raspberry Pi. The same script also saves the readings into a .CSV file which has the date as file name so that I have every day a unique file with a full day's worth of data in it. I have implemented within a PHP page an open source JavaScript charting library in order to plot the readings:
Also within the same PHP page I can select from a drop down menu the .CSV files mentioned above. To achieve that I have used the foreach construct.
Anyway please see below my PHP code:
<html>
<center>
<iframe width="800" height="600" src="http://SERVER_IP_ADDRESS/graphs.php" frameborder="0" allowfullscreen="" scrolling="no$
</center>
<head>
<script type="text/javascript"
<script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/dygraph/2.1.0/dygraph.css" />
</head>
<body>
<div id="graphdiv2"
style="width:700px; height:500px;"></div>
<script type="text/javascript">
g2 = new Dygraph(
document.getElementById("graphdiv2"),
"20180508.csv", // path to CSV file
{rollPeriod: 7,
showRoller: true} // options
);
</script>
</body>
</html>
</head>
<body>
<?php
$filename = 'CSV_index.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);
?>
<form method="post" action="">
<select name="menu">
<option selected value="base">Please Select</option>
<?php foreach($eachlines as $lines){ //add php code here
echo "<option value='".$lines."'>$lines</option>";
}?>
</select>
<button type="submit" name="submit" >Submit</button>
</form>
<?php
if(isset($_POST["submit"]))
{
$selected_value=$_POST["menu"];
?>
Now this is what I would love to achieve: once I select the .CSV file from the drop down menu, I would like it to appear automatically in the line below:
"20180508.csv", // path to CSV file
This is where the library finds the path to the .CSV file to plot that graph. So by selecting a specific .CSV I can then plot the relevant graph for a specific day.
I have tried the following but of course both didn't work:
"$selected_value", // path to CSV file
"'$selected_value'", // path to CSV file
Many thanks in advance for your kind kelp.