Possible to make my images called from a database to be a link to another page?

≡放荡痞女 提交于 2019-12-13 04:41:14

问题


<?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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!