Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created March 25, 2024 18:54
Show Gist options
  • Save AbhishekGhosh/8b799b29a3171b60b3d0c8978913d0e6 to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/8b799b29a3171b60b3d0c8978913d0e6 to your computer and use it in GitHub Desktop.
get_data.php
<?php
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Query to fetch latest water level
$sql = "SELECT level FROM water_level ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Output data of each row
$row = $result->fetch_assoc();
echo $row["level"];
} else {
echo "0";
}
$conn->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment