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 (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 26.23), (now(), 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