Strange count effect.

        lcd.setCursor(0, 1);
        lcd.print("   ");
        lcd.setCursor(0, 1);
        lcd.print(tempval);

Looks like a candidate to put into a function to be called when required. If you need to use the technique to print variables in different places on the display then the function could be passed row, column and variable name to be printed to make it more generally useful.

If you have the spare room on the display it is more efficient to always print spaces after value to avoid the need to position the cursor twice. A variation would be to print only the number of spaces required after the variable depending on its length, thus avoiding the possibility of printing over other data or text already on the screen.