你好,我是新来的,我试图弄清楚PHP和MySQL是如何工作的。 我试图在页面上显示图像,但现在只能显示文本。如何添加图像,以便它不仅显示图像的位置?
in phpMyAdmin我创建了下表。
dvdshop2
。 与有5个类别的DVD。
description text 255.
id int primary_key auto increment.
image varchar 255.
price decimal 10,2.
title varchar 100.
我在我的数据库中有一个电影,这样的照片。
id title price description image
1 Star Wars 12.99 sci-fi movie /dvdshop2/images/sw.jpg
我运行XAMPP的服务器,其中dvdshop2
是我htdocs文件夹的工作文件夹。 当我在浏览器中打开页面时,我想要数据库中的数据显示图片sw.jpg
而不是文本/dvdshop2/images/sw.jpg
。
这是我的代码。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
$conn = new mysqli("127.0.0.1","root","","dvdshop2");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM dvd";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "id: " . $row["id"]. " - Title: " . $row["title"]. " " . "<br>" . "- Price:" . $row["price"] . "<br>" . " Description: " . " " . $row["description"] . " " . "<br>" . " image: " . "<br>" . $row["image"] . "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</body>
</html>
图片标签是''它在任何html手册中都有描述。 –
您需要学习更多html:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img – aynber
@VictorSmt如果您要编辑问题以格式化表格最少使用ASCII艺术工具,如https://ozh.github.io/ascii-tables/ – Styphon