I am new to the PHP Programming. I retrieve image dynamically from the folder and fetch into the webpage.Now, I want to know how will I give link to the image to redirect to the other page? The most important thing is, I retrieve image dynamically not statically.
This is the code I use to retrieve the image:
$data = mysql_query("SELECT image FROM product1");
$file_path = 'image/';
while($row = mysql_fetch_assoc( $data )) {
$src=$file_path.$row['image'];
echo "<img align='left' src=".$src." height='430' width='466' > ";
}
write the code like below
<a href="redirect_page.php"><img src="your_folder_name/<?php echo $image_name;?>" /></a>
think it will solve your problem
Put your img
tag within an anchor tag.
"<a href='".$link."'><img align='left' src='".$src."' height='430' width='466' > </a>";
$data = mysql_query("SELECT image FROM product1");
$file_path = 'image/';
while($row = mysql_fetch_assoc( $data )) {
$src=$file_path.$row['image'];
$link = 'YOUR_REDIRECT_LINK';
echo "<a href='".$link"'><img align='left' src=".$src." height='430' width='466' ></a>";
}
$data = mysql_query("SELECT image FROM product1");
$file_path = 'image/';
while($row = mysql_fetch_assoc( $data )) {
$src=$file_path.$row['image'];
echo "<a href='redirect.php'><img align='left' src='".$src."' height='430' width='466' ></a>";
}
Above is the same code you supplied, with the following changes:
1 - I've wrapped the image in an anchor tag, to an example redirect page (redirect.php)
2 - I've added single quotes around the src attribute's value, on the img element
Wrap the image that you're echoing in an tag.
Then, using the php variable $src, build a dynamic link for each image:
If you want it to open in a new window, use the target="_blank" attribute in the link.
$data = mysql_query("SELECT image FROM product1");
$file_path = 'image/';
while($row = mysql_fetch_assoc( $data )) {
$src=$file_path.$row['image'];
echo "<a href="{$src}" target="_blank"><img align='left' src=".$src." height='430' width='466' ></a>";
}
in php you can give use this code- {{ HTML::image($your _table_name->image, $your _table_name->title) }}
and all the images from the database will come.