Page 1 of 1
assign links to images drawn from directory
Posted: Thu Jun 24, 2010 3:22 pm
by kyleiwaniec
I have four large thumbnails on the right hand side of my page which are drawn from a directory.
Is there a way to associate a unique link with each image? (so that when you click on a image it takes you to its page)
http://www.mercercountyrealtors.com/pre ... index2.php
my php snippet, which BTW, I got from this forum,Thks.
Code: Select all
<?php
$files = glob("featured_images/*.*");
for ($i=0; $i<=3; $i++) {
$num = $files[$i];
//print $num."<br />";
echo '<li><img style="width:180px; height:140px; padding: 3px; margin:5px; border: 1px solid #ccc;" src="'.$num.'" ></li>'; }
?>
Re: assign links to images drawn from directory
Posted: Thu Jun 24, 2010 3:38 pm
by AbraCadaver
I'm not sure if you've already built these pages or they will be built dynamically, but this is more dynamic:
Code: Select all
$id = (int)$num;
echo '<li><a href="property.php?id=$id">
<img style="width:180px; height:140px; padding: 3px; margin:5px; border: 1px solid #ccc;" src="$num">
</a></li>';
Then on the property.php page you use this to get the passed id:
Re: assign links to images drawn from directory
Posted: Thu Jun 24, 2010 5:39 pm
by kyleiwaniec
It seems this will take me to the id on the page property.php.
What I'm trying to do is have each image link to its own page. So image1.jpg links to featured1.php, image2.jpg links to featured2.php, and so forth.
The pages will not be dynamically generated (for now).
However, I can name the pages sequentially, if that helps. (featured1.php, featured2.php, etc..)
Maybe I'm going about it the wrong way ?
Re: assign links to images drawn from directory
Posted: Thu Jun 24, 2010 6:11 pm
by kyleiwaniec
OK, I think I'm getting it. The property.php page will contain only the image I clicked on (and hopefully other associated data).
pardon my ignorance, is that right?
But then I'll have to make my whole website dynamic and I'm not really knowledgeable enough to do that.
Re: assign links to images drawn from directory
Posted: Thu Jun 24, 2010 6:52 pm
by kyleiwaniec
OK, I got what I was looking for:
Code: Select all
<?php
$files = glob("featured_images/*.*");
for ($i=0; $i<=3; $i++) {
$num = $files[$i];
//set target path for image
$path = "featured" . $i . ".php";
//print $num."<br />";
echo '<li><a href='.$path.'><img style="width:180px; height:140px; padding: 3px; margin:5px; border: 1px solid #ccc;" src="'.$num.'" ></a></li>';
}
?>
Thanks for all your help
