Well, I can successfully fetch a result set from a MySQL database via PHP, and display its contents on a web page via HTML.
I can also write JavaScript functions.
Here's the problem: I have no idea where, physically, I need to put my PHP code to have the array result set show up in my JavaScript functions!
Here's my PHP:
<?php
$photos = array();
[code to fill this array with results from database]
?>
I have this directly under the head. Also under the head:
<script>
prevPhoto() {
var jPhotoArray = <?php echo json_encode($photos); ?>;
for (var i = 0; i < jPhotoArray.length; i++){
if (thePhoto.src == jPhotoArray[i]['photo']) {
if (i + 1 != jPhotoArray.length) {
thePhoto.src = jPhotoArray[i + 1]['photo'];
}
}
}
}
</script>
(For the curious, the intended functionality is to create a manual slideshow of photos that users can flip through by clicking "forward" and "backward" for as long as there is another picture behind the one currently displayed.)
But when I launch the page and take a look at the memory, the variable jPhotoArray is null.
What am I doing wrong?