will the picture id always be incremental? ie; if you decide you don't like picture 12 and delete it, will you fill that in, or do you want to work around it?
if its the latter, you need to use a query to find the next greater (or lesser) value wil somthing similar to
$currentid = intval($_GET['pid']); //escape value
SELECT pid FROM table WHERE pid > $currentid ORDER BY pid ASC LIMIT 1
//or better yet...
SELECT min(pid) FROM table WHERE pid > $currentid
alternatively, if the photo id will always be incremental, you can just use php and +/- 1 the current id,
$nextpage = $currentid+1;
$prevpage = $currentid-1;
note that for both you'll need to find the biggest and smallest number, so it doesn't print when its on the last/first photo,
$next = ($currentid != $last_id) ? "<a href='...?pid=".$nextpage."'>next</a>": '';
$prev = ($currentid != $first_id) ? "<a href='...?pid=".$prevpage."'>prev</a>": '';