I am trying to retrieve a set of values from a database using PHP, and then I would like to pass those retrieved values to javascript, so that they can be displayed to the user, used to construct other elements, etc.
Javascript in Index.php:
<script type="text/javascript">
;(function($) {
$(document).ready( function() {
var $img = $("#image1").imgNotes2({
onReady: function() {
var notes = [<?php include $_SERVER['DOCUMENT_ROOT'].'/home/inc/mapmarkers.php'; ?>]
this.import(notes);
}
});
});
})(jQuery);
</script>
And mapmarkers.php;
<?php
require '../assets/setup/mapdb.inc.php';
$sql = "SELECT * FROM markers WHERE id >= 1;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
// SQL ERROR
return false;
}
else {
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$index = 0;
$string = "";
while($row = mysql_fetch_assoc($results)) {
$MarkerInfo = array(
'id' => $row['id'],
'author' => $row['author'],
'party' => $row['party'],
'permission' => $row['permission'],
'enabled' => $row['enabled'],
'xpos' => $row['xpos'],
'ypos' => $row['ypos']
);
echo ($MarkerInfo);
}
}
?>
Currently, Index.php loads and runs just fine but none of the output from mapmarkers.php is actually echoed into the script tag. What have I mucked up?
I am including mapmarkers.php because of security reasons but if there is another safe way to do this please let me know.
Looked around quite a bit and couldn't truly find anyone else with this exact problem, apologies in advance if this has already been asked/solved.