$x=$row[0]; if ( 0 < $x || $x < 30 ) { $x=30; $total=$total+$x; } else if ( $x >= 30 ) { $reminder=$x%6; $added=6-$remainder; $x= $x+added; $total=$total+$x; }