Hello I am trying to output my mysqli database to a js file after encoding it, I have no trouble encoding it with json_encode
but how can I get it into a js file (updating every time the mysqli data is updated)
$mysqli = new mysqli('localhost','user','password','myDatabaseName');
$myArray = array();
if ($result = $mysqli->query("SELECT * FROM tablename")) {
$tempArray = array();
while($row = $result->fetch_object()) {
$tempArray = $row;
array_push($myArray, $tempArray);
}
echo json_encode($myArray);
}
$result->close();
$mysqli->close();
Any help or insight would be great! thanks