New to this but loving it. I have a database of URLs of pictures of cats that I want to display in a webpage. I wrote some php to do this but all I'm seeing it the URL of the image and not the image itself. Here is my full code:
新到这,但爱它。我有一个猫图片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>
As you can see, the database name is "cats" with a table called "cats_test" that holds all of the images in a column called "image" you can find a screenshot of that here
正如您所看到的,数据库名称是“cats”,其中有一个名为“cats_test”的表,它在一个名为“image”的列中保存所有的图像
You can also see the URLs being displayed instead of images here
您还可以在这里看到url而不是图像
I've probably done something really stupid, so would appreciate any help you guys might have!!
我可能做了一些非常愚蠢的事情,所以非常感谢你们的帮助!!
1 个解决方案
#1
3
Replace your :
取代你的:
echo "<td>".$cats_test['image']."</td>";
With :
:
echo "<td><img src='".$cats_test['image']."' ></td>";
#1
3
Replace your :
取代你的:
echo "<td>".$cats_test['image']."</td>";
With :
:
echo "<td><img src='".$cats_test['image']."' ></td>";