I am a php beginner and in order to create a chart I need a php file with json data, which is created through a database query. My query code looks as follows:
<?php
$servername = "xyz";
$username = "x";
$password = "y";
$dbname = "z";
// Create connection
$mysqli = new mysqli($servername, $username, $password, $dbname);
$data1 = [];
$sql = "SELECT ROUND value, timestamp FROM table";
$result = mysqli_query($mysqli, $sql);
while ($row = mysqli_fetch_array($result)) {
array_push($data1,[intval($row['timestamp']),doubleval($row[0])]);
}
?>
Now I want to display the code by printing the query so it has a json format like:
[ [12000000000000,5.5],
[12000000000000,5.5],
.......
]
I tried several things like print_r etc. but nothing quite got me there.