使用php和mysql将图像显示为链接

时间:2016-08-27 02:51:13

标签: php html mysql

我正在使用PHP和MYSQL创建照片库。我希望法师和他们下面的标题有一个超链接。图像和其下的标题的超链接将转到同一网页。如何使用php和mysql在网页上显示图像及其标题?重要的是图像和标题上有链接。 Image of the PhpMymin database and table 这是代码:

<!DOCTYPE html>
<html>
<body>

<?php
mysql_connect ("localhost", "root", "");
mysql_select_db ("display_images");
$result = mysql_query("SELECT * FROM table1");


echo "<table>";

while ($row = mysql_fetch_array($result)) {

    echo "<tr>";
    echo "<td>"; ?> 
    echo '<a href="'$row ["imagelink"].'"><img src="img/'.echo $row ["images1"].'" width="150" height="150" alt=""> <br>'

echo $row ["caption"] </a>' </td>; echo "</td>";

    echo "</tr>";
  }

echo "</table>";



?>
</body>
</html>

1 个答案:

答案 0 :(得分:-1)

根据您的需要尝试以下代码,在您的代码中,您没有使用适用于html代码和php变量的enquotes ...

<!DOCTYPE html>
<html>
<body>

<?php
   mysql_connect("localhost", "root", "");
   mysql_select_db("display_images"); // Please check with your database name
   $result = mysql_query("SELECT * FROM table1");

   echo "<table>";

   while ($row = mysql_fetch_array($result)) 
   {
       $image_link = $row['imagelink'];
       $image_path = $row['image1'];
       echo "<tr>";
       echo "<td>";
       echo "<a href=".$image_link."><img src=".$image_path." width='150' height='150' alt='' /> <br>";
       echo $row['caption']."</a>"; 
       echo "</td>";
       echo "</tr>";
   }

   echo "</table>";

?>

我希望这会对你有所帮助,请随意发表评论。