Don't forget to mark this answer as "solved" if this solves your problem.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Time, Type FROM MyTable";
$result = $conn->query($sql);
// Declare 4 variables to store time and type so you can compare to previous.
$time1 = "";
$type1 = "";
$time2 = "";
$type2 = "";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$time2 = $row["Time"];
$type2 = $row["Type"];
if ($type2 == $type1) {
$time1 = $time2;
$type1 = $type2;
}
else {
echo "At $tim2 type changed from $type1 to $type2";
$time1 = $time2;
$type1 = $type2;
}
}
}
else {
echo "0 results";
}
$conn->close();
?>
You can shorten the code for the loop and write this:
while($row = $result->fetch_assoc()) {
$time2 = $row["Time"];
$type2 = $row["Type"];
if ($type2 != $type1) {
echo "At $tim2 type changed from $type1 to $type2";
}
$time1 = $time2;
$type1 = $type2;
}
To exclude the first result when the loop starts, write this:
while($row = $result->fetch_assoc()) {
$time2 = $row["Time"];
$type2 = $row["Type"];
if ($type2 != $type1 && $type1 != "") {
echo "At $tim2 type changed from $type1 to $type2";
}
$time1 = $time2;
$type1 = $type2;
}