After the results are displayed, we let the user know what page they are currently on, and the total number of pages that exist. This is not necessary but it is nice information for the user to know.
Then we generate the navigation. We assume that if you are on the first page, then you don't need a link to the first page. And as it is the first result, no previous page exists. So we check (if ($pagenum == 1) ) to see if we are on page one. If we are, then nothing happens. If we aren't on page one, then we use PHP_SELF and the page numbers to generate links to both the first page, and the the previous page.
We do almost the exact same thing to generate the links on the other side, however this time we are checking to make sure we aren't on the last page. If we are, then we don't need a link to the last page, nor does a next page exist.