问题
<?php
include 'dbconnect.php';
$query = mysql_query("SELECT * FROM champicons ") or die("Error: " . mysql_error());
echo "<table border='1' width='100%' >";
echo "<tr>";
$i = 0;
while($row = mysql_fetch_array($query)){
if($i++%10 == 0) echo '</tr><tr>';
$image = $row[2];
echo "<td>";
echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';
echo "</td>";
}
echo "</tr>";
echo "</table>";
?>
I'm calling 117 images which are small icons into a table with 10 images per row, I want these images to be links to a specific page for each image, is this possible through the way I have my code now?
EDIT: Example
Picture 1 links to /picture1.php Picture 2 links to /picture2.php etc.
EDIT: SOLVED
while($row = mysql_fetch_array($query)){
if($i++%10 == 0) echo '</tr><tr>';
$name = $row[1];
$image = $row[2];
echo "<td>";
echo "<a href='$name'>";
echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';
echo "</a>";
echo "</td>";
回答1:
Just Add an anchor tag around the image.
echo "<td>";
echo "<a href='url here'>";
echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';
echo "</a>";
echo "</td>";
回答2:
Create an image.php file. In the file, create a function that will parse an ID from the URL. In your table of images, link them to /images.php?Id=thepictureid
来源:https://stackoverflow.com/questions/22366910/possible-to-make-my-images-called-from-a-database-to-be-a-link-to-another-page