Include 'sample' in SQL query and put it into a function for reuse.
Suppress notice of undefined index.