If I understand rightly then all you need to do is pass the variable along the URL string.
For instance on one page you may have the link as showpage.php?pic=002 and on another it may be showpage.php?pic=003
The value that you assign to "pic" is then available as $pic in the target page. So in showpage.php you could have:
echo '<img src="/images/'.$pic.'.jpg">';
You could also do it by detecting the referrer I suppose, but this seems easier.