As I am a novice in PHP scripting, I wrote a PHP script that has HTML tags which creates a UI and later want to update its UI values via a PHP code block.
Something like below:
index.php
<div>
<div id="ecg">
<br/>
<br/>
<br/>
<p><b>Electrocardiac Diagram </b></p>
<p><b>(ECG) </b></p>
</div>
<div>
<img id="ecgimg" src="images/ecg.jpg" alt="ECG" height="200" width="300" align="middle">
</div>
<br/>
<br/>
</div>
</div>
Later as stated above in same file:
<?php
while (1){
$read = $file->read();
$s=0;
$y=0;
$ecg="";
$sp="";
$bp="":
$oxy="";
$temp = "";
............
$ecg=$read;
.....
?>
How can I update the HTML text div id="ecg" with the one I have read from file - say I want to make the text as
(ECG Normal)
Once the page is shown to the user you can't use plain PHP to update the page as the page is no longer on the server but on the client's computer.
You need to use Javascript and AJAX to read the file and update the page.
You could read this to help you:
https://api.jquery.com/jQuery.ajax/
http://www.w3schools.com/jsref/met_win_setinterval.asp
Update:
Here is what your html file should look like:
<div>
<div id="ecg">
<?php
$read = $file->read();
echo $read;
?>
</div>
<div>
<img id="ecgimg" src="images/ecg.jpg" alt="ECG" height="200" width="300" align="middle">
</div>
<br/>
<br/>
</div>
Here is the javascript:
<script>
setInterval(readFile, 3000);
function readFile() {
$.ajax({
url: "readFile.php"
})
.done(function( data ) {
$('#ecg').html(data);
});
}
</script>
In the readFile.php all you need is:
<?php
$read = $file->read();
echo $read;
?>
And that's it.