MySQL update row cell with 0 value with value from closest row that does not have 0 value
SET @var :=0;
UPDATE records
SET time= (@var :=CASE WHEN time = '0' THEN @var ELSE time END)
ORDER BY id;


Fiddle

Add DESC after ORDER BY if you want to update time with the time value of the next id.