fixed logic problem in advance pagination script.