gpt4 book ai didi

php - 使用 PHP 显示来自 MySQL 数据库的图像

转载 作者:可可西里 更新时间:2023-11-01 08:11:06 26 4
gpt4 key购买 nike

对此很陌生,但很喜欢。我有一个要在网页中显示的猫图片的 URL 数据库。我写了一些 php 来做到这一点,但我看到的只是图像的 URL,而不是图像本身。这是我的完整代码:

<html>
<body>
<h1>Katz!!</h1>

<!--Connect to Database-->
<?php
$db_host = "localhost";
$db_username = "Alex";
$db_pass = "";
$db_name = "cats";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mySQL");
@mysql_select_db("$db_name") or die ("No database");

$sql="SELECT * FROM cats_test";
$records = mysql_query($sql);
?>

<!--Populate table from database-->
<table border="2" cellpadding="1" cellspacing="1">
<tr>
<th>cat table</th>
</tr>
<?php
while($cats_test=mysql_fetch_assoc($records)) {
echo "<tr>";
echo "<td>".$cats_test['image']."</td>";
echo "</tr>";
}
?>
</table>
</body>
</html>

如您所见,数据库名称是“cats”,有一个名为“cats_test”的表,该表将所有图像保存在名为“image”的列中,您可以找到该 here 的屏幕截图

您还可以看到显示的是 URL 而不是图像 here

我可能做了一些非常愚蠢的事情,所以非常感谢你们提供的任何帮助!!

最佳答案

替换你的:

echo "<td>".$cats_test['image']."</td>";

与:

echo "<td><img src='".$cats_test['image']."' ></td>";

关于php - 使用 PHP 显示来自 MySQL 数据库的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33642437/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com