Sounds like you just need to add a "previous value" variable, e.g.:
$prev = null;
while($row = mysql_fetch_assoc($exec)) {
if($row['foo'] != $prev) {
// value changed!
}
// process DB row...
// update previous value for next iteration
$prev = $row['foo'];
}