I'm sending my mysql result to an associative array and then encoding with JSON
$showDisplayResult = $mysqlConn->query($getDisplayPage);
while($row=mysqli_fetch_assoc($showDisplayResult))
{
$rows[] = $row;
}
$showDisplays = json_encode($rows);
ANd in my main page I'm using javascript to grab this, parse it and append the correct variables into my URL. The functionality seems to work but it only shows undefined as the variables in the URL.
Here's the javascript:
<script type="text/javascript">
let obj = <?php echo $showDisplays; ?>;
//obj = JSON.parse(obj);
let params = new URL(document.location).searchParams;
params.set("pageID", obj.pageID);
params.set("display", obj.display_id);
let url = window.location.href.split('?')[0];
let nextURL = url + "?" + params.toString();
window.setTimeout(function () {
window.location.href = nextURL;
}, obj.duration * 1000);
console.log(obj);
</script>
So my URL is now showDisplay.php?display=undefined&pageID=undefined
How can I get this to parse the JSON correctly?
UPDATE:
If I echo $showDisplays, this is the JSON that prints:
[{"pageID":"104","page_type_id":"1","display_id":"3","slide_order":null,"duration":"56","active":"1","background_img":null,"panel_id":"96","panel_type_id":"1","page_id":"104","cont_id":"148","contID":"148","content":"\r\n\r\n\r\n<\/head>\r\n\r\nThis is full content<\/p>\r\n<\/body>\r\n<\/html>"},{"pageID":"116","page_type_id":"1","display_id":"3","slide_order":null,"duration":"54","active":"1","background_img":"images\/BG_spring.svg","panel_id":"113","panel_type_id":"1","page_id":"116","cont_id":"165","contID":"165","content":"\r\n\r\n\r\n<\/head>\r\n\r\nThis background should be green<\/p>\r\n<\/body>\r\n<\/html>"}]
So on page load i want the url to have display=3&pageID=104 then after 56 seconds (its duration) it should refresh and th URL should be display=3&pageID=116 for 54 seconds, and then keep the loop
JSON.parse(obj)commented out?obj.pageIDetc???