Remember the previous value and only perform the display (print old value with background color then print new value in foreground color) if the value has changed.
Please use codetags. (please read How to get the best out of this forum and modify your post accordingly.)