I'd like to visualize last 144 temperature data from MySQL database on my website. Now I have the following code:
<?php
$servername = "localhost";
$username = "_accounts";
$password = "---";
$dbname = "_accounts";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT `t` FROM `WbabZwvgf` ORDER BY `id` DESC LIMIT 144";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$t = $row["t"];
}
} else {
echo "0 results";
}
$conn->close();
Now if I echo $t after i have declared in "while" like this:
while($row = $result->fetch_assoc()) {
$t = $row["t"];
echo $t." ";
}
seems everything OK, but I can't save each values as php variables like $t1=t[0], $t2=t[1], $t3=t[2]...etc, even during the "while". Could you help me how to save the selected data into PHP variables?