First post here on stack overflow.
I'm creating a YouTube stream monitor to keep an eye on multiple streams simultaneously and all was going well until i tried to work out how to update the data. Ive connected to the API, got the data into a json format and got the page working well. The problem now comes with updating the data and whilst i could just refresh the data section every x seconds that would cause the embedded video to refresh every time.
<?php
$url = "data_template.json"; //static json for development
$json = file_get_contents($url);
$data = json_decode($json);
$html = null;
foreach ($data->data as $program) {
$html .= "<li id='1'>
<img src='images/test.jpg' width='100%'>
<!--YouTube Stream <iframe> embed -->
<button>Public</button><button disabled>Preview - Not Enabled</button>
<h4> {$program->broadcast->title} ( {$program->broadcast->id} )</h4>
<p id='broad'>Broadcast Status: {$program->broadcast->lifeCycleStatus} </p>
<p>Stream Status: {$program->stream->streamStatus} and {$program->stream->healthStatus} </p>
<p>Last Updated: {$program->stream->lastUpdate} </p>
</li>";
};
echo $html;
?>
I would like to update the variables within the paragraphs of each list but am struggling to work out how to get to them. Ive tried the below but it doesn't seem very efficient.
<script>
var x = document.getElementById("1");
x.querySelector("#broad").innerHTML = "Hello World!";
</script>
Would i be better adding an intermediate step and having different variables in the HTML that can be individually ID'd and updated?