I'd like to show some data of my database with Javascript. Here's my PHP script:
$arrayDatabase = array();
$statement = $link->prepare("SELECT project.ID, project.titel, project.subtitel, project.plaatje, project.beschrijving, project.link FROM project" );
$statement->execute();
$statement->bind_result($ID, $titel, $subtitel, $plaatje, $beschrijving, $site);
while($statement->fetch()){
echo '
<div class="singleProject" id="'.$ID.'">
<img src="'.$plaatje.'" alt="'.$titel.'" />
<div>
<h2>'.$titel.'</h2>
<div><p>'.$subtitel.'</p></div>
</div>
</div>
';
$arrayRij= array($ID, $beschrijving, $site);
array_push($arrayDatabase, $arrayRij);
}
$statement->close();
But if I use json_encode to get the array to Javascript, it won't work.
var jsArray = <? echo json_encode($arrayDatabase); ?>;
EDIT: In my browser there is only a ';' after var jsArray =
The weird thing is. If a use a multidimensional array on my own like:
$phpArray = array(array("foo", "bar"), array("foo", "bar"));
My script works.