This seems weird to me. Wouldn't the last_id be @lastID here? You are moving to the next page so you want to know the last id that was loaded.