0

我在 html 中创建了一个表格,在每个单元格中我想将其中的图像链接到 php 中的记录,但我对如何去做有点困惑,请帮忙。

<td>
<?php
$con=mysqli_connect("server","username","password","db");
$sql = "SELECT imgurl FROM Workshop_products WHERE id=XXX";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($result);
?>
<img src="<?php echo $row['imgurl'] ?>" />
</td>

尝试向每个单元格添加类似的内容,但它只显示图像。谢谢

4

2 回答 2

0

将图像包装到<a>-tag 中:

<?php
$link = "user.php?id=$row[id]"; // example: this is the page you want to link to
$img  = $row['imgurl'];
?>

<a href="<?php echo $link; ?>"><img src="<?php echo $img; ?>" /></a>
于 2013-11-05T01:36:50.477 回答
0

我认为您正在尝试显示数据库中表示的所有图像,所以也许是这样的:

<?php
$con=mysql_connect("bt2201-1213.bimserver2.com","ihamzadb","xK56K7S6","ihamzadb");
$sql = "SELECT imgurl FROM Workshop_products";
print "<table>";
while($row = mysql_fetch_assoc($sql)){
    print "<td><a href ='" . $row['imgurl'] . "'><img src = '" . $row['imgurl'] . "'></a></td>";
}
print "</table>";
于 2013-11-05T01:38:47.890 回答