PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
create table AllinOne ( ID int primary key auto_increment, DayTime datetime, Temperature double ); insert into AllinOne (DayTime, Temperature) values (13:31:03, 26.23), (2021-09-29 13:30:55, 26.23), (2021-09-29 13:30:49, 26.23), (2021-09-29 13:30:45, 26.23), (2021-09-29 13:30:27, 26.23), (2021-09-29 13:30:03, 26.23), (2021-09-29 13:29:55, 26.23), (2021-09-29 13:29:48, 26.23), (2021-09-29 13:29:44, 26.23), (2021-09-29 13:29:26, 26.23);
Copy Clear
Copy Format Clear
<?php $conn = &$mysqli; $sql = ("SELECT ID, DayTime, Temperature FROM AllinOne ORDER BY ID DESC LIMIT 10"); $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { echo "id: " . $row["ID"]. " - DayTime: " . $row["DayTime"]. " - Temperature " . $row["Temperature"]. PHP_EOL; } } else { echo "0 results"; } $sql2 = "SELECT Temperature, COUNT(*) as duplicates FROM ( SELECT ID, DayTime, Temperature FROM AllinOne ORDER BY ID DESC LIMIT 10 ) LastData GROUP BY Temperature"; $result2 = $conn->query($sql2); if ($result2->num_rows > 0) { // output data of each row while($row2 = $result2->fetch_assoc()) { echo $row2["duplicates"]. PHP_EOL; } }
Show:  
Copy Clear