move out sql logic from Display to Db class
move user to the last page if last record is deleted. Fixes #640
show pagination if user manually enter too great page number.