DISCLAIMER:
I don't have access to a PHP environment to try this out, but you're almost there...
Looking at your code, $image_path, would have to be a local filesystem path... something lile "/var/www/himages".
In order to create a link to an image, you would need a root URL that you can build on, something like "http://www.yoursite.com/images/"
Assuming the following values:
(it doesn't matter how closely these match what you're doing, it's just the principle of the thing...)
$image_url = "http://www.yoursite.com/images/"
$id = "10102"
$p = "x"
$url1 = "<a href=\"" . $image_url . $id . "_" . $p . "." . "jpg\">Click here to see image</a>";
Would build upa string in url which contains a html to create a text link which reads "Click here to see image".
In the above case, the link it has built up is to
http://www.yoursite.com/images/10102_x.jpg
where hopefully your image is stored.
I don't think that's quite what you want, is it? My guessis that you want to display a thumbnail and then show the pig picture when someone clicks on it.
Do you have the thumbnails and big pictures already prepared? Is that what $p is for? I'll now assume that a $p value of "b" indicates the "big" image and "t" indicates the "thumbnail" iamge.
If that's the case, and the images are already prepared, then you would now need code something like...
$url1 = "<a href=\"" . $image_url . $id . "_" . "b". "." . "jpg\"><img src=\"" . $image_url . $id . "_" . "t". "." . "jpg\"></a>";
Now my assumptions are probably well wide of the mark, but hopefully this will give you a start.