getChartData.php

mail@pastecode.io avatar
unknown
php
a month ago
498 B
0
Indexable
Never
<?php
include("koneksi.php");

// Periksa koneksi
if ($koneksi->connect_error) {
    die("Connection failed: " . $koneksi->connect_error);
}

$sql = "SELECT * FROM sensor ORDER BY time_stamp DESC limit 7 ";
$result = $koneksi->query($sql);

$data = array();
if ($result->num_rows > 0) {
    // Ambil data dari setiap baris
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
} else {
    echo "0 results";
}
$koneksi->close();

echo json_encode($data);
Leave a Comment